Observations { } for await - Compilation Error

Hi,

I was watching the video WWDC25: What's new in Swift

Compilation Error

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

  1. 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) }
}
1 Like

This is a known issue in the first seed. See the release notes here: Xcode 26 Beta Release Notes | Apple Developer Documentation

1 Like

@donny_wals Thanks a lot!! I was breaking my head over this.

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

1 Like

Based on Xcode 26 Beta 3 release notes it states that

Resolved Issues

  • Fixed: Observations is not available. (152888116)

However I am still getting a compilation error on Xcode 26 Beta 3.

Am I missing something?

Same here, neither Xcode26b3 compiler nor swiftly nightly works.

  • Xcode26b3 can't compile as it does not know Observations.
  • swiftly nightly compiles ( with -Xfrontend -disable-availability-checking ) but crashes on start
  • docker nightly works fine with -Xfrontend -disable-availability-checking
1 Like

@jollyjinx Thanks a lot for checking

  • Hopefully it gets fixed in Xcode 26 Beta
  • Also would be nice to correct the release notes for Xcode 26 Beta 3.
2 Likes