I am assuming there is a simple reason for this, but I'm stuck. If don't comment out os_log
code, the below fails to compile. Is there a reason the $0
can't be used in the contextMenu
?
import SwiftUI
import os.log
struct ContentView: View {
var capitals = ["Kuala Lumpur", "Tokyo", "Canberra"]
@State private var test: Bool = false
var body: some View {
VStack {
ForEach(capitals, id: \.self, content: {
Text($0)
.contextMenu(menuItems: {
Button(action: {
//os_log(.info, "Capital selected: ", $0)
self.test.toggle()
}, label: {
Text("Hello!")
Image(systemName: "hand.raised.fill")
})
})
})
Text(test ? "true" : "false")
.padding()
}
}
}