ios – What is the workaround for using the @Observable and @Enviorment Macro as part of the Apple SwifftUI Tutorial?


When using these macros, I receive the following errors:

@Observable Issue: Unknown attribute ‘ObservableObject’

@Environment Issue: Cannot convert value of type ‘ModelData.Type’ to expected argument type ‘KeyPath<EnvironmentValues, Value>’, Generic parameter ‘Value’ could not be inferred

On the following page link-to-page at Step 2 of Section 4, I am told to do the following :

Step 2: Declare a new model type using the Observable() macro.

and then I am told to the following on Step 3:
In LandmarkList, add an @Environment property wrapper to the view, and an environment(_:) modifier to the preview.

I have tried setting my class to adhere to the ObservableProtocol and setting my var landmarks to @Published as per another stack overflow post, but I do not know what I am doing nor what it meant. It seemed to remove the error message though for the @Observable issue.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img