I am trying to learn to write swift. I am very proficient MS VB, which I have been using for almost 20 years. The Book I am learning from is:
SwiftUI for Masterminds. I have got to chapter 7 with no problem. The exercise I am having a problem with Listing 7-5. The error I am getting is:
Thread 1: Fatal error: No Observable object of type ApplicationData found. A View.environmentObject(_:) for ApplicationData may be missing as an ancestor of this view. I have spent the last 2 days rechecking my code. The MacBook I am using was purchased in May this year, is 16 in, M4 Max chip, 128 G ram.
Firstly I want to thank you for reading this post.
If you provide your code, I might be able to help determine if it’s an error there, or something with the Xcode project itself.
I can’t speak for other languages, but sometimes an error message is far separated from the line of code that’s the root of the issue, though usually there’s at least some clue. Doing a search online of the error message can pull up any where it’s been addressed before.
One good way to learn Swift for free is through the “playgrounds” app. I would start with the course called “get started with apps”. After that there’s one called “keep going with apps”. ( If you’re still working on the basics of swift apps. )
The YouTuber “Paul Hudson” has a course. Haven’t tried it, but I think his Swift videos are some of the best out there, so I’m assuming it’s at least decent.
There’s also the Apple “App Dev. Tutorials”, such as “Passing data with bindings”, which are excellent walkthroughs, but don’t cover everything as far as I know.
The newer the book, the better, because swift is known for having features and syntax being deprecated, replaced, or modified, regularly. Even an edition of a book from a year ago will be missing a significant amount of stuff.
I’m also new to swift, and a beginner coder, so take this with a grain of salt.
Lastly, to maximize the chance of getting a response, I would:
Use the error being thrown as the title of this topic, or a description of you’re problem
Then open a new topic specifically about your textbook / course question.
Note that SwiftUI is just one of GUI frameworks, and is not a part of the language itself. SwiftUI is available on Apple platforms only, unlike the Swift language in general. If you are interested in Swift as a language, there is the official The Swift Programming Language book.