Live data from Hacker News

Ask HN: Resources to Learn macOS Development?

news.ycombinator.com

51–60 of 91 posts

Re: Ask HN: Resources to Learn macOS Development?

#51
post #28
post #27

I'm just finshing up my first macOS app. I went with SwiftUI because I was new and didn't want to learn an "old" tech. The reality is outside of very basic stuff, SwiftUI is not capable of doing a lot of stuff, so I ended up have to learn not only AppKit as well, but how to fuse AppKit into SwiftUI and fuse SwiftUI into AppKit. My advice is don't be attracted by the shiny toy that is SwiftUI. It's a steaming pile to…

It’s probably more productive to mention what about SwiftUI is a “steaming pile of dung”. For most mobile UI, you can spit out a working design faster than w/ AppKit. It doesn’t even have to be one or the other, you can meld both. What’s the value in talking about SwiftUI being incapable when you don’t mention what you can’t do in it.

It doesn’t support a lot of what you can do in AppKit at the moment. There are also many bugs in it where it will throw asserts or stop working or draw incorrectly.

Re: Ask HN: Resources to Learn macOS Development?

#52
Started a new app last year using Stotyboards and AppKit and haven’t regretted it for a second. I use SwiftUI on iOS devices on a daily basis and I don’t have to dip into UIKit very often anymore, but AppKit on macOS was always more mature than UIKit let alone SwiftUI. Plus SwiftUI still has rough spots on macOS.

If you want to go for the typical macOS look & feel stick with AppKit.

Resources: barely any

Apparently you’re either not interested in macOS development or you’re way too experienced to need help.

Re: Ask HN: Resources to Learn macOS Development?

#53

"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…

> 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/

Re: Ask HN: Resources to Learn macOS Development?

#54

Do a little iOS dev since that has 100x more learning resources. Once you grok iOS, you'll be at home with macOS since they follow the same patterns. Stick with storyboards, don't bother with SwiftUI (no, really, don't do it) and try to use as much default out of the box behaviour as possible, instead of wondering 'how do I do that X thing I did on platform Y'.

Storyboards are slow compared to Live Preview, and lead beginners to adopt bad patterns like Massive View Controllers rather than composable/testable SwiftUI components. Not to mention its horrendous XML format.

> Storyboards are slow compared to Live Preview

Citation needed. Even on Apple silicon, I'm not even sure Live Preview can crash faster than Interface Builder and it has no shortage of practice.

> lead beginners to adopt bad patterns like Massive View Controllers rather than composable/testable SwiftUI components

There is no requirement at all on how big a storyboard is and allowing things to occupy the same *.storyboard where they would have to separate XIB files is an imporvement where it is useful.

> Not to mention its horrendous XML format

Where it does not come at other costs, standard formats (XML) are easier to operate with external tools over bespoke formats (turing complete Obj-C or Swift code). The properties in those files were more numerous than their SwiftUI counterparts, but they served a purpose.

Working with SwiftUI and the bonanza of implied default behaviors required to achieve its terseness add new salience to the idea "it is better to be explicit than implicit".

Re: Ask HN: Resources to Learn macOS Development?

#55
post #7

I would suggest Cocoa Programming for Mac OS X , even though it's based on Objective-C and the book is old. That means it's based upon older versions of Xcode and Mac OS (like ~10 years old). Conceptually it's a good book, but because of it's age the code examples, etc are outdated. The publisher does have forums which can be helpful: https://forums.bignerdranch.com/c/cocoa-programming-for-os-x... They also have a Sw…

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 AppKit code in Swift is pretty sweet.

Re: Ask HN: Resources to Learn macOS Development?

#57
Just do it.

I started with one of the Big Nerd Ranch books many years ago. I spent a few evenings reading it, and then spent a few hours dabbling with Objective C in XCode. I then got frustrated and put it down for a few years until I took a job that involved some Objective C. (This was over a decade ago.)

It's surprisingly easy to learn the details of system calls by Googling and looking at stack overflow. Yes, the semantics are different, but the general theory is the same. There's a main thread that's often referred to as the main run loop. Accessing your UI outside of the main run loop (thread) is a big no-no.

As much as I want to vouch for learning Swift, (it's really easy if you have a Java / C# background,) there's also a good reason to be proficient in Objective C: It's just a layer on top of C. It's very easy to wrap C APIs in Objective C and then call them from Swift. This is important, because if you're trying to do something low-level, you will need to interact with a C API. (Although, Swift fixes a lot of the weirdness of Objective C if all you want is something that's like Java / C#.)

FWIW: There are some semantic differences that can take some time to adjust to. In Objective C, sending a message to a null object is a no-op instead of a runtime exception. Swift appears memory safe, but I've done things with timers that cause surprise crashes.

Re: Ask HN: Resources to Learn macOS Development?

#59
post #7

I would suggest Cocoa Programming for Mac OS X , even though it's based on Objective-C and the book is old. That means it's based upon older versions of Xcode and Mac OS (like ~10 years old). Conceptually it's a good book, but because of it's age the code examples, etc are outdated. The publisher does have forums which can be helpful: https://forums.bignerdranch.com/c/cocoa-programming-for-os-x... They also have a Sw…

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 need for it. I also think most people accustomed to newer programming languages would probably find it arcane in some areas and tedious in many others (although I personally like it for what it is and don't regret the time I spent with it, I definitely felt like I was making things harder on myself by using it).

Re: Ask HN: Resources to Learn macOS Development?

#60

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/

Pretty recent, I check it every once in a while to see what’s going on. Of course, with macOS generally most of the changes happen around WWDC ;)

SwiftUI on macOS is currently ok for a few usecases. One is little document apps. Emphasis on little, this is going to be things that wrap an image or a text file or something. The API is reactive so it’s not really designed for complex/partial file formats. Another good usecase is just pure drawing/animation. This code will look identical on macOS and iOS and is very easy to write with SwiftUI. Finally, the last thing that mostly works is just lists of content. Not table views, those aren’t very good yet. I’m talking about Twitter-like content, as in a media viewer in list form.

What doesn’t work well is anything that has to do with controls (either they look very ugly, the control doesn’t exist, or SwiftUI has no concept of some significant portion of the control). If you want to do like focus loops or right clicks or anything complicated, forget it. (Some of these are getting fixed piecemeal, but AppKit has like a thousand little things that make good apps and it’ll be a while before they are all fixed.)

By way of example, I actually have some small apps that show this off well. https://github.com/saagarjha/EffectivePower is a little view-only document shoebox style app. It’s 100% SwiftUI, has one main screen that is a hand-drawn graph, and some auxiliary UI. This makes it about as good as it could be for using the framework. Making the graph was a delight. Making it perform well was a little bit of work but not too bad. The document abstraction mostly works except SwiftUI expects me to be able to create new documents and I’m just a viewer app so I need to crash if you try to make a new document. The sidebar is a List, which is fine, but I actually wanted it to be a Table. However Table selection asserts right now if you update its selection faster than the NSTableView that backs it animated. Of course in SwiftUI there is no concept of animation duration so you can’t really stop this from happening. You can also zoom the graph in the app. On Monterey if you tried to zoom a couple of times the system magnification gesture just stopped working silently. On Ventura I believe they have fixed this, or at least it isn’t trivially broken anymore. This is common for SwiftUI.

By way of contrast, https://github.com/saagarjha/VirtualApple is also pretty simple but it’s 100% AppKit. I had originally written it in SwiftUI but it’s just not possible to make it be a good Mac citizen. It is “document based” but because it deals with multi-gigabyte VMs I can’t actually let it do the default document based behavior, which includes making hidden revisions whenever the files update (which means you get a dozen secret copies of the VM). In AppKit I can just turn this all off and still look identical to any other system app. (Caveat: if I want the recent files menu and don’t want to use a storyboard, this is actually not available even in AppKit without SPI). Also, I have a little configuration screen which is all buttons and checkboxes. AppKit lets me align it precisely how I want so it looks nice. In SwiftUI it would look pretty awful.

Post reply on HN