Hello,
I'm having some difficulties trying to customise a SwiftUI list-detail splitview using List and OutlineGroup:
The model used is provided in Apple documentation OutlineGroup.
The contentView is
struct ContentView: View {
@State var itemString = String()
var body: some View {
HSplitView {
MyOutLine(title: "MyOutLine", itemString: $itemString)
.frame(width: 200, height: 300
, alignment: Alignment(horizontal: .leading, vertical: .top))
.padding()
MyView(itemString: itemString)
}
}
}
The left view is
struct MyOutLine: View {
let title:String
@Binding var itemString:String
@State private var selection: FileItem?
var body: some View {
List(selection: $selection) {
OutlineGroup(data, children: \.children) { item in
Text ("\(item.description)")
.onTapGesture {
selection = item
itemString = item.description
}
.listRowBackground(
selection == item ?
Color.gray
:nil
)
}
}
.listStyle(.sidebar)
.onAppear { itemString = "No selection"}
}
}
The right view is:
struct MyView: View {
let itemString:String
var body: some View {
VStack{
Spacer()
HStack {
Spacer()
Text(itemString)
Spacer()
}
Spacer()
}
}
}
The result works but I have 2 problems:
The selection works but the detail view is updated only when I click the text but not when I click the rest of the row. This results in the detail view not being sync with the list selection.
I would like to customise the colour of the selected row but listRowBackground does not seem to work.
Is there a way to fix this
Thank you in advance
Jean Marie
Post
Replies
Boosts
Views
Activity
Hello,
For educational purpose, I try to use a POSIX semaphore sem_t instead of a dispatch_semaphore_t in a sandbox macOS Obj-C app.
When using sandbox, the semaphore code creation :
sem_t * _unixSemaphore;
char nameSemaphore[64] = {0};
snprintf(nameSemaphore, 22, "/UnixSemaphore_sample");
_unixSemaphore = sem_open(nameSemaphore, O_CREAT, 0644, 0);
fails, receiving SEM_FAILED and the errno is 78 (not implemented)
However, the sem_t _unixSemaphore is created and works fine when I disable sandbox I my entitlements.
Is there a way to fix this?
Thank you in advance
Jean Marie
Hi,
I just notice a few days after having to setup for a new Box TV received from the TV and Internet provider, that my Apple TV does not work anymore.
The led is off and the HDMI port connected to the AppleTV is not shown on the TV configuration.
I'm convinced that there was somehow a current failure during the setup of my new box TV.
I change the HDMI cable but without success
Question:
How to make sure that the Apple TV is dead or simply in standby. In the late, how to restart it
Many thank
Jean
Hi,
I migrate an audio project using AVAudioEngine from Objective-C to Swift.
All objects are the same but in Swift instead of Objective-C.
The application uses the microphone input and analyses it via a renderCallback process calling the FFT of the Accelerate framework.
The session has an important CPU usage:
- TheObjective-C version keeps the CPU usage at 8%
- The Swift version is on average at 20%.
I have isolated the code that originates the increase and it is due to a method analysing the returned samples in order to summarize them.
Parameters:
arrMagCount = 12
arrMag is an array of float containing the magnitude of the frequency range related to the index
samplesCount = 4096
samples is a pointer of a float array delivering the magnitude of each bins used
Result:
Each arrMag[index] is updated with the magnitude related to the range of frequency underlying the index
The Objective-C version calls a C process for the function
The Swift version was developped in swift since we cannot mix C code and Swift code in the same source
func arrMagFill(arrMagCount:Int, samplesCount:Int, samples:UnsafePointer<Double>, arrMag:UnsafeMutablePointer<Float>, maxFrequency:CGFloat) {
// Zeroes arrMag.
memset(arrMag, 0, arrMagCount)
for iBin in 0..<samplesCount {
for iLoop in 0..<arrMagCount {
if maxFrequency < g.FreqMetersRangeMaxValue[iLoop] {
arrMag[iLoop] = Float(samples[Int(iBin)])
break
}
}
}
}
When I use a C equivalent code via an Objective-C bridge Header, the CPU usage is back to [8..12] on average.
Is there a way in Swift to obtain directly the same performances ?