Skip to content

Instantly share code, notes, and snippets.

@siracusa
Created June 8, 2023 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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