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.

As an update, I tried copying the minimal example to a Playground and it ran fine. And removing the : NSViewRepresentable makes it compile fine. I have no idea what is happening.

Both examples build cleanly for me (in a new macOS SwiftUI project).
(I have to supply example 1 with a dummy implementation of HFTextView)

Xcode 13.3 (13E113)

Can't conform to NSViewRepresentable
 
 
Q