When I tried to compile code I got the following compilation error" Cannot find 'Observations' in scope
Configuration
Xcode: 26
macOS: 15.5 (24F74)
Run on: iOS 16 Pro simulator
Question
How to fix the compilation error?
Code
import Observation
@Observable
class Player {
let name: String
var score: Int = 0
init(name: String) {
self.name = name
}
}
#Playground {
let player = Player(name: "Holly")
let values = Observations { //Cannot find 'Observations' in scope
let score = "\(player.score) points"
return "\(score) and \(player.name)"
}
player.score += 2
player.item = .banana
for await value in values { print(value) }
}
Observations do work with the current docker nightly even though not with the swiftly nightly (compiles but crashes due to missing symnbols there)
with docker installed you can use the swift nightly:
docker run --rm -v "$PWD:/home" -w /home -ti swiftlang/swift:nightly-main swift -swift-version 6 foo.swift