DEV Community

Discussion on: Adding an NSTableView to a SwiftUI View

Collapse
 
markknopper profile image
Mark Knopper

Hi, thanks for this tutorial about NSTableView in SwiftUI. Would it be possible for you to upload your project that does this successfully? I keep running into errors and crashes on initializing from NSViewControllerRepresentable and makeNSViewController. I am currently getting this when returning from makeNSViewController:

-[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: EntityNSTableViewController in bundle (null).

followed by a EXC_BAD_ACCESS crash when the window is brought to the front.

Collapse
 
hugh_jeremy profile image
Hugh Jeremy

Hi Mark, sorry for my slow reply! I have been doing some more work with NSTableView in SwiftUI recently, so it's possible I could smash something together to upload... I have a few macOS apps in the pipe that I might be able to open source. I'll try to do so soon!

Collapse
 
gabeklavans profile image
Gabriel Klavans

I'd also love an example project! I'm learning to build a MacOS app and it's tough to learn aspects of NSTableView concurrently with SwiftUI concepts...

Thread Thread
 
hugh_jeremy profile image
Hugh Jeremy

Yeah NSTableView definitely requires a totally different mindset than SwiftUI. I'd recommend building some stuff in AppKit to get used to the "old" way of doing things. It's so common to need to drop back down into AppKit, and NSViewRepresentable becomes very important. Another example is AuthenticationServices - To add a "Sign in with Apple" button you're back in AppKit land writing @objc interface implementations!