lorenzofiamingo/swiftui-shared-object
`@SharedObject` is an alternative to `@StateObject`, `@ObservedObject`, `@EnvironmentObject` to handle `ObservableObject`.
Usage
Retrieve the shared object with the given id or, if not present, create a shared object with an initial value:
@SharedObject("A") var letterA = Letter()If you are sure that the object is already been created you can just retrieve the shared object:
@SharedObject("A") var letterA: LetterYou can give a default initial value to the class, so you don't need to specify in each view you think the object will be created:
final class Letter: SharableObject {
var value: String
init(_ value: String) {
self.value = value
}
static var initialValue: Self {
.init("A")
}
}Installation
- In Xcode, open your project and navigate to File β Swift Packages β Add Package Dependency...
- Paste the repository URL (
https://github.com/lorenzofiamingo/swiftui-shared-object) and click Next. - Click Finish.
Other projects
Package Metadata
Repository: lorenzofiamingo/swiftui-shared-object
Default branch: main
README: README.md