Can't use @observable

after i import swiftui, there's no @observable?? it shows unknown attribute...

and i cant import observation or swiftdata

import Foundation import SwiftUI

@Observable

class BusinessModel{

var businesses = [Business]()
var selectedBusiness: Business?
var input: String = ""
var service = dataservice()

}

If you cannot import Observation or import SwiftData it's because you do not have the required environment/target settings, such as target iOS 17, macOS 14. As mentioned in the comments in your StackOverflow question.

To expand on workingdogintokyo’s comment…

after i import SwiftUI, there's no @Observable?

That’s expected. To access @Observable, you need to do this:

import Observation

If that’s failing, it’s likely that you need to upgrade to Xcode 15. The Observation framework requires iOS 17 [1] and thus you need the iOS 17 SDK, which means Xcode 15.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Likewise macOS 14 and the other Apple platforms.

Can't use @observable
 
 
Q