PickyBikers wrote:
I am trying to follow along with a book, "SwiftUI Cookbook". It makes extensive use of previews.
Apple has its own tutorials. But being Apple, they are really hard to find. You would think they would be listed somewhere prominently on the developer site. Instead, you have to have already seen them somehow and know to Google them.
Here is one site, for example: Introducing SwiftUI | Apple Developer Documentation
Ordinarily in these situations, one might say "start from there", but again, this is Apple. While are tutorials on that page, they don't seem to link to this other, much more extensive tutorials page: Develop apps for iOS | Apple Developer Documentation. The "Start here" buttons seem to be the best way to go.
I can't really fault people for pushing Previews. Apple certainly does that too. But then Apple pushes lots of things that are really bad ideas. You're welcome to try them if you want. I did too. Your experience sounds pretty typical. I sure don't miss them.
If I turn off all the previews, then I am left with the simulator and compiling after every change?
Yes and no.
By default, Xcode is constantly compiling. It wasn't so bad before, if you had a fast Apple Silicon computer. But recent versions of Xcode 14 and 15 have effectively broken that. I recommend going into Xcode Settings and turning off "live preview" (no relation to the other previews that you've been talking about) so that it only builds when you try to build and run.
Otherwise, two things happen. 1) You'll start getting lots of phantom errors. You know the code it correct. It compiles and runs perfectly. But after doing that, it complains about errors. You can clear the errors, but they'll come right back. You can search the internet for a solution. Many people report this problem. Many people claim to have found a solution. No solution exists.
2) You actually do have an error. Xcode doesn't care. It will run the app anyway. It runs the previous version, which is obviously useless. Whether this is the simulator, a real device, or a Mac, it takes a few seconds to realize it is happening, wait for it, then quit. It gets annoying after a few dozen times.
I think that would take forever on my 2017 iMac.
Anything with modern Apple software is going take forever on a 2017 iMac. I think I've mentioned this before, but I don't even know which iMac you have. Some of those 2017 iMacs aren't just "not Apple Silicon", they are horribly, horribly slow. They will struggle with basic, built-in apps. Xcode? No más, no más!
I'm just not sure about where to go from here.
Should I find a book on IOS programming that does not use SwiftUI? Most of what is out there says use SwiftUI.
It's hard to say. SwiftUI is definitely what all the hip kids are using now. But what isn't often mentioned is that it follows the "react" principle. If you aren't familiar with the levels of absurdity that computer science PhD's can descend to, then you probably don't realize what that means. It isn't something made for humans. It's really twisted.
Above, you mentioned compiling after every change, as if that was a bad thing. That's how SwiftUI works. It runs your entire program every time any data point changes. Redraws every screen. Sets everything up fresh. Every time the user presses a key or clicks a button. Just so you know.
Should I buy a new M3 based iMac? If so, how much memory do I need for programming?
You've got a 2017 iMac. It's simply a question of how much you want to punish yourself. Personally, I would recommend one of those new 15" Mac Book Airs. I have the previous M2 generation and it is noticeably faster than my older, but still very fast 2021 M1 MacBook Pro. My old 2017 top-of-the-line MacBook Pro is painfully slow compared to either of these.
16 GB of RAM is fine. It's more the SSD speed than anything else. For all I know, your iMac still has a mechanical hard drive.
It is really disappointing to find out that creating the basic IOS hello world app using SwiftUI fails to run as expected and it could cost more than $1000 do get it to run previews.
Suggestions on a better way to start programming iPhones are welcome.
It's a brutal world. There are millions of developers, just for Apple platforms. Neither Apple, nor anyone else, needs any more developers. It's amazing that there are as many tutorials and support for beginners as there is. Of course, the idea is that you'll work cheaper and complain less than us greybeards.
But what they neglect to mention is that it takes years to gain minimal competency. You can build simple apps with SwiftUI. You can even do it on a 2017 iMac. But you have to stick with it. And wait for it. And put up with more bugs than you can imagine. You aren't doing anything wrong. You just shouldn't believe the marketing shtick or what people say on the internet. This is as good as it gets.