Live data from Hacker News

Ask HN: Resources to Learn macOS Development?

news.ycombinator.com

61–70 of 91 posts

Re: Ask HN: Resources to Learn macOS Development?

#61

"I am looking for explanations that will help me build a conceptual understanding of macos UI development." it depends on your learning style of course, but if you like lecture / course-style learning, i highly recommend paul hegarty's CS193P, it will definitely give you the in-depth, conceptual explanations you're describing. while it is an iOS dev course (taught at stanford, lectures are freely offered online), the…

I can't vouch for any of the more recent versions of CS193P, but the original incarnation on iTunes U in ~2008 was my introduction to Objective-C and C, and I found it invaluable. I remember Loren Brichter's guest lecture on the development of Tweetie being really insightful.

Personally, I'd skip Swift / SwiftUI until you have a decent understanding of the Objective-C frameworks underpinning the vast majority of the macOS/iOS SDKs.

Re: Ask HN: Resources to Learn macOS Development?

#62
I assume those questions are rhetorical, but let me try to answer them in a very terse form just so you have some terms to search the docs for. Assuming you want to use AppKit.

> What is the equivalent of the event loop under macos?

NSRunLoop / CFRunLoop. You rarely need to interact with it directly. Typically only the main run loop on the main thread is important, if you want to do something on a different thread you typically use dispatch queues (GCD=grand central dispatch) instead of run loops.

> Do events bubble up through the hierarchy?

Yes, most events go up the responder chain, which is typically view -> superviews -> window -> app. You typically respond to events by implementing methods defined in a protocol (like "keyDown" or "insertTab") or by implementing delegate methods ("windowWillClose"). Sometimes you also have to listen for notifications from NotificationCenter.

> What is the right way to persist user configuration?

NSUserDefaults for everything that can be serialised into a number/string/dictionary easily, and the application support directory for anything you want to store in files.

Re: Ask HN: Resources to Learn macOS Development?

#63
Be aware any application you distribute must be signed now, or gatekeeper will not allow it to run. This means you must pay the $100 yearly apple developer fee, apple wants to make sure you're not economically disadvantaged. There are no exceptions even for students or open source. Only a licensed nonprofit may be able to waive it.

Re: Ask HN: Resources to Learn macOS Development?

#64

Earlier quoted context omitted.

It's possible to wrap UIKit in SwiftUI (using UIViewRepresentable and UIViewControllerRepresentable), to do the things that SwiftUI can't yet do by itself. Those deficiencies will slowly be filled out, of course - there's no reason to stay exclusively with UIKit any more. More significantly, SwiftUI introduces a new declarative paradigm - very different from what was before. It makes a lot of previously laborious thi…

On iOS. The situation is very different on macOS, which is what was being discussed here.

These APIs exist for NSView (AppKit) as well:

https://developer.apple.com/documentation/swiftui/nsviewrepr... https://developer.apple.com/documentation/swiftui/nsviewcont...

Or is that not what you meant?

Re: Ask HN: Resources to Learn macOS Development?

#65

Earlier quoted context omitted.

This is the best answer for hobby Mac programming for AppKit in Objective-C. As others have said, SwiftUI is the future and you might want to instead look at that if you can find a decent guide to it -- a lot of what's on the web is very badly obsolete already. It's a very different model. Folks, there will come a point where new UI features don't ship anymore for AppKit. Telling people not to learn SwiftUI is extrem…

I made a few simple Mac apps in Objective-C during the pandemic in 2020, and I was struck by how hard it was to find tutorials and examples on how to do anything in Objective-C. It's possible I was looking in all the wrong places, but it seems like everyone assumes you're using Swift at this point. I would advise against learning Mac development with Objective-C except to people who have a specific interest in it or…

There are three reasons for using Objective-C:

- Performance: Sometimes the automatic conversion between Objective C and Swift types causes performance issues. Using Objective-C for some hot paths can be a lot faster. Sometimes just using NSString instead of String in Swift can also do the trick.

- Legacy code: For most projects, there is no point in converting 100s of legacy Objective C classes to Swift. Just leave the old parts in Objective C, and call them from Swift. Rewriting just risks breaking stuff.

- Interface with C/C++ code. Swift has some nice bridging that make calling C code easy (such as automatic conversion of swift strings), but some APIs like socket() are close to unusable in Swift, because they require complicated casts that are impossible to understand. Easier to write those parts in Objective C.

Re: Ask HN: Resources to Learn macOS Development?

#66

Earlier quoted context omitted.

This is the best answer for hobby Mac programming for AppKit in Objective-C. As others have said, SwiftUI is the future and you might want to instead look at that if you can find a decent guide to it -- a lot of what's on the web is very badly obsolete already. It's a very different model. Folks, there will come a point where new UI features don't ship anymore for AppKit. Telling people not to learn SwiftUI is extrem…

SwiftUI is not usable yet on the Mac. I can't talk about its state on iOS, but on the Mac you will run into deal breaking limitations even for the most basic apps. If you want to make Mac apps, learn AppKit. You can use AppKit from Swift just fine, there's no need to use Objective C. Some of the text APIs are a bit cumbersome to use with Swift because of the different string semantics, but for the most part writing A…

This. You can also use SwiftUI inside NSHostingView. So you can do parts of your app in swift ui (preferences panel would be a good place to start).

But for more involved stuff this is not production ready yet (except you want to do major reworks with each new SwiftUI revision).

Re: Ask HN: Resources to Learn macOS Development?

#67

Earlier quoted context omitted.

> while it is an iOS dev course (taught at stanford, lectures are freely offered online), the newest lectures are using swiftUI for UI, so pretty much all of it will translate to doing macOS dev. They absolutely will not. SwiftUI on macOS and SwiftUI on iOS are very different beasts. For the latter, it is at the point where you can actually kind of make a good app in it with the majority of your code only using the f…

> On the other hand making a good macOS app using only SwiftUI is pretty much impossible. How recent was your experience with it? I'm assuming your characterization is accurate, but since SwiftUI is being used for notable bits of Ventura, I'm curious what OS version it reflects. https://troz.net/post/2022/swiftui-mac-2022/

Apple has always the joker card of being allowed to use private APIs. They have also a lot of money an can waste developer time on rewriting their SwiftUI applets constantly.

If you don’t have that kind of resources it would be wise to use the tried and true stack and switch over to the shiny new thing once it’s actually stable.

Re: Ask HN: Resources to Learn macOS Development?

#69
This might not be a popular opinion but it was what worked for me: - Research a little about PostScript and the display version. - NextStep Developer Documentation [1] - Apple older documentation (it is archived, but covered a lot of stuff)

Why this instead of a book? MacOS X UI is the result of many years of experiment and technologies. Going over the historical view gave me time to build a mental framework to work on instead of pushing things as they are today. MacOS is also changing so much that the documentation gap only gets worse with time.

Storyboards, SwiftUI, iOS, UIKit are noisy in that sense because they solve problems that you might not understand from the get go.

Understanding Objective-C is also crucial because besides SwiftUI, the backbone was made with Objective-C characteristics in mind. But this one I don’t have good references for besides Smalltalk books and Clang documentation.

[1] http://www.nextcomputers.org/NeXTfiles/Docs/NeXTStep/3.3/nd/

Re: Ask HN: Resources to Learn macOS Development?

#70

"I am looking for explanations that will help me build a conceptual understanding of macos UI development." it depends on your learning style of course, but if you like lecture / course-style learning, i highly recommend paul hegarty's CS193P, it will definitely give you the in-depth, conceptual explanations you're describing. while it is an iOS dev course (taught at stanford, lectures are freely offered online), the…

> while it is an iOS dev course (taught at stanford, lectures are freely offered online), the newest lectures are using swiftUI for UI, so pretty much all of it will translate to doing macOS dev. They absolutely will not. SwiftUI on macOS and SwiftUI on iOS are very different beasts. For the latter, it is at the point where you can actually kind of make a good app in it with the majority of your code only using the f…

How about using SwiftUI on Mac via Catalyst?
Post reply on HN