Hey,
not sure where exactly to post this. I hope this is fine here.
I've been following the Observation Pitch with great interest and a first experimental implementation seems to have been merged into the main branch of Swift: https://github.com/apple/swift/pull/63725
I've never downloaded or used a development snapshot of Swift from the main branch before (from Swift.org - Download Swift) but I thought I'd give it a try.
I downloaded the snapshot from March 7, installed it and told Xcode to use it. That seems to work.
However, I can't figure out how to enable the experimental "Observation" feature. In the PR, I found the flag SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION and from some other examples I found on the internet I figured that I'd need to add the following to my Swift Flags in Xcode:
-Xfrontend -enable-experimental-observation
Unfortunately, I get an error when I try to build the project:
<unknown>:0: error: unknown argument: '-enable-experimental-observation'
I've tried several variations of this, like -swift-enable-experimental-observation and -SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION.
I'm not sure if I'm doing something wrong. Or is the feature not fully "public" yet?
I'd appreciate any help with this 
With the toolchain selected, I think you can
import Observation
to use these features. @Philippe_Hausler please correct me if that's wrong.
Doug
1 Like
That is correct; as of current I believe you need to still specify the enablement of the macro feature however.
1 Like
That should not be needed, either. Both SE-0382 and SE-0389 have been accepted, so all of the macro functionality used by Observation is enabled by default.
Doug
2 Likes
Are you using it on Lunux or Mac?
With the toolchain selected, I think you can
import Observation
Ah, thanks, didn't know that. Importing does work fine, without adding any kind of other Swift flags
Unfortunately, I can't use the @Observable macro. It gives me this error:
External macro implementation type 'ObservationMacros.ObservableMacro' could not be found for macro 'Observable'; the type must be public and provided via '-load-plugin-library'
I've seen the -load-plugin-library in the Macros Example Repository (that example project does build and works fine for me) and tried to copy over the Swift flags, including this -load-plugin-library, but it doesn't work. I don't really find anything on the internet about this flag.
Are you using it on Lunux or Mac?
I'm on a Mac.
1 Like