Created
June 8, 2023 18:09
-
-
Save siracusa/02d8667694d9dc1295362ddeda82987a to your computer and use it in GitHub Desktop.
Lazy properties in an @observable class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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