Post

Replies

Boosts

Views

Activity

Can't conform to NSViewRepresentable
Hey all. I'm trying to wrap an NSView (HFTextView, from HexFiend) with a wrapper conforming to NSViewRepresentable. struct HexView: NSViewRepresentable { typealias NSViewType = HFTextView var data: Data func makeNSView(context: Context) -> HFTextView { let view = HFTextView() view.data = data return view } func updateNSView(_ nsView: HFTextView, context: Context) { nsView.data = data } } The error that I get is Type 'HexView' does not conform to protocol 'NSViewRepresentable' Candidate has non-matching type '(Context) -> HFTextView' [with Coordinator = Void] Candidate has non-matching type '(HFTextView, Context) -> ()' [with Coordinator = Void] and it offers to make the the makeNSView and updateNSView functions again for me. I thought this might be an issue with how I'm building HexFiend's framework, so I tried something basic, replacing HFTextView with NSTextView like so: struct HexView: NSViewRepresentable { typealias NSViewType = NSTextView var data: Data func makeNSView(context: Context) -> NSTextView { let view = NSTextView() return view } func updateNSView(_ nsView: NSTextView, context: Context) { } } But I get the same error. Copying and pasting code samples that do it also get the same error, or it complains about a missing typealias. I must be missing something obvious, there's no way this could be this broken. I'm using Swift 5, Xcode 13.3, building for Mac. Any help you could render would be most appreciated.
2
0
1k
Mar ’22