Rob Fahrni

Rob Fahrni

Stream for Mac Dev Note

RibbitIn iOS development land we have UITableViewController and UITableViewCell for building lists.

On the Mac – AppKit – we have, with my limited knowledge, NSTableView, NSTableCellView, and NSCell. Apple’s developer docs say:

Beginning with macOS v10.7, you can use NSView objects (most commonly customized NSTableCellView objects) instead of cells for specifying rows and columns. You can still use NSCell objects for each row and column item if you prefer.

For some reason my brain finds that paragraph confusing. I need to dig a bit deeper into the docs but my initial read leaves me believing NSCell is not NSView based?

No matter, it’s not a big deal. I already have Stream for Mac populating the table and selecting a row displays the article for it. I have a very long way to go, mind.

Something I have considered doing is wrapping up the AppKit classes with classes that implement UITableViewController and UITableViewCell so I could at least have a familiar interface to work with, but that might be a bit of work for very little gain.

Oh, if you’re wondering why I’m doing the Mac version in AppKit instead of SwiftUI? It’s simple: I’d like to learn a bit about AppKit. It’s apparent we’re headed for a SwiftUI only world. That’s fine. I’ll be on board at some point – I’ve already done a bit.

Oh, FYI, it’s not that difficult to move from UIKit to AppKit. Minor things, like the paragraph I mention above, but AppKit existed long before UIKit.

Here’s a very simple example.

#if os(iOS) import UIKit typealias HSColor = UIColor typealias HSFont = UIFont typealias HSImage = UIImage typealias HSView = UIView #elseif os(macOS) import AppKit typealias HSColor = NSColor typealias HSFont = NSFont typealias HSImage = NSImage typealias HSView = NSView #endif

In my code I’ve been using HS versions of these class types and they work as expected. If I find a missing method on the Mac, I extend the class to include the missing method. Easy!

Here’s one example of that. extension NSColor { static var darkText: HSColor { return HSColor.black } static var lightText: HSColor { return HSColor.white } static var label: HSColor { return HSColor.labelColor } }

Still plugging away.