Skip to content

Instantly share code, notes, and snippets.

@siracusa
Created June 8, 2023 18:09
Show Gist options
  • Save siracusa/02d8667694d9dc1295362ddeda82987a to your computer and use it in GitHub Desktop.
Save siracusa/02d8667694d9dc1295362ddeda82987a to your computer and use it in GitHub Desktop.
Lazy properties in an @observable class
import Cocoa
import Observation
//@Observable
class User {
// If @Observable is applied to this class, compilation
// of this property declaration fails with the error:
//
// 'lazy' cannot be used on a computed property
//
lazy var id : Int = {
return Int.random(in: 1...100)
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment