@Observable and other SwiftUI Macros

The sessions showing off the new SwiftUI macros are missing a key element.... How are they enabled within XCODE?!??!?

For instance the session "Discover Observation in SwiftUI" starts with the code block.

@Observable class FoodTruckModel {
var orders: [Order] = [] var donuts = Donut.all }

Well.... Something is missing here! I'm sure it's that I need to import something.... but for an intro session it MIGHT be important to mention what needs to be imported and any other requirements. Because right now all I'm getting is "Unknown attribute 'Observable'"

So far this is a VERY disappointing WWDC. I got all excited about VisionOS... Nope, all the SDK isn't being release for a month. Reality Composer Pro... Not out yet. SwiftUI macros... Sure let's dive right in to step 6 and not tell you what you need to get started with this feature.

  • I agree that leaving out the critical import Observation was a huge oversight. I spent at least 20-30 minutes trying to figure out what I was missing.

  • Agreed; I also had to resort to Googling it and trying to figure out what was missing. Even the slides did not show the import needed.

Add a Comment

Accepted Reply

By the way, the answer to your question is that @Observable comes from a new framework called Observation, so you need to import Observation at the top of source files that use the new behaviors.

Replies

By the way, the answer to your question is that @Observable comes from a new framework called Observation, so you need to import Observation at the top of source files that use the new behaviors.

Could you please update your guidebook : https://developer.apple.com/tutorials/swiftui/handling-user-input here as it's mentioned about observable macro but doesn't say we need to import anything , ive spent over 1h to figure out were my programme was not following. your guidance until I came across this topic and it solves my issues