Hey all,
I'm quite a newbie at SwitUI development and I've been almost a week trying to solve a problem but i'm really frustrated about.
The thing is very simple I guess. I just trying to send a @Binding var to a NSView class and print the value in my console on click in a SwiftUI View.
This is my code:
import SwiftUI
class TapHandlerView: NSView {
@Binding var text: String
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
init(text: Binding<String>) {
self._text = text
super.init(text: text) // Line error -> Argument passed to call that takes no arguments
}
override func mouseDown(with event: NSEvent) {
super.mouseDown(with: event)
print(text)
}
}
struct TapHandler: NSViewRepresentable {
@Binding var text: String
func makeNSView(context: Context) -> TapHandlerView {
TapHandlerView(text: $text)
}
func updateNSView(_ nsView: TapHandlerView, context: Context) {
}
}
struct ItemView: View {
@State var text: String = "Hello!"
var body: some View {
VStack {
Text("Click here!")
}
.overlay(TapHandler(text: $text))
}
}
_
This is the error I get:
super.init(text: text)
Argument passed to call that takes no arguments
_
For more context, I come from here: https://stackoverflow.com/questions/64194207/swiftui-foreachs-onmove-modifier-stop-working-if-the-content-view-has-tap-ges
I hope that someone can help me and sorry if is a silly question, I feel like I'm missing something very basic but im blocked with it.
Thank you!