{"id":13536976,"url":"https://github.com/lorenzofiamingo/swiftui-shared-object","last_synced_at":"2025-10-24T01:48:52.449Z","repository":{"id":37566278,"uuid":"284071735","full_name":"lorenzofiamingo/swiftui-shared-object","owner":"lorenzofiamingo","description":"A new property wrapper for SwiftUI ObservableObject.","archived":false,"fork":false,"pushed_at":"2024-04-21T13:08:20.000Z","size":30,"stargazers_count":66,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-07-10T14:34:54.300Z","etag":null,"topics":["propertywrapper","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lorenzofiamingo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-31T15:42:54.000Z","updated_at":"2024-07-10T14:35:10.079Z","dependencies_parsed_at":"2024-07-10T14:34:53.606Z","dependency_job_id":"64fa0468-69ae-4e7a-8980-c5e61c8a8f05","html_url":"https://github.com/lorenzofiamingo/swiftui-shared-object","commit_stats":null,"previous_names":["lorenzofiamingo/swiftui-sharedobject"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzofiamingo%2Fswiftui-shared-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzofiamingo%2Fswiftui-shared-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzofiamingo%2Fswiftui-shared-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lorenzofiamingo%2Fswiftui-shared-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lorenzofiamingo","download_url":"https://codeload.github.com/lorenzofiamingo/swiftui-shared-object/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238200774,"owners_count":19433098,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["propertywrapper","swift","swiftui"],"created_at":"2024-08-01T09:00:52.964Z","updated_at":"2025-10-24T01:48:52.389Z","avatar_url":"https://github.com/lorenzofiamingo.png","language":"Swift","funding_links":[],"categories":["Samples"],"sub_categories":[],"readme":"# SwiftUI SharedObject 🍱\n\n`@SharedObject` is an alternative to `@StateObject`, `@ObservedObject`, `@EnvironmentObject` to handle `ObservableObject`.\nIf you need to have multiple objects of the same class persisted among multiple view instances, it's difficult to handle the situation with other wrappers: with `@StateObject` the object will deinit with the view and be generated only for the specific view instance, with `@EnvironmentObject` you can bind only one instance of the same class for each Environment and with `@ObservedObject` is difficult to propagate object in nested views.\n\n`@SharedObject` simply stores the objects using an identifier, so you can retrieve it each time you'll need it.\n\n## Usage\n\nRetrieve the shared object with the given id or, if not present, create a shared object with an initial value:\n```swift\n@SharedObject(\"A\") var letterA = Letter()\n```\nIf you are sure that the object is already been created you can just retrieve the shared object:\n```swift\n@SharedObject(\"A\") var letterA: Letter\n```\nYou 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:\n```swift\nfinal class Letter: SharableObject {\n\n  var value: String\n\t\t\n  init(_ value: String) {\n\tself.value = value\n  }\n\t\t\n  static var initialValue: Self {\n\t.init(\"A\")\n  }\n}\n```\n\n## Installation\n\n1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...**\n2. Paste the repository URL (`https://github.com/lorenzofiamingo/swiftui-shared-object`) and click **Next**.\n3. Click **Finish**.\n\n\n## Other projects\n\n[SwiftUI VariadicViews 🥞](https://github.com/lorenzofiamingo/swiftui-variadic-views)\n\n[SwiftUI AsyncButton 🖲️](https://github.com/lorenzofiamingo/swiftui-async-button)\n\n[SwiftUI MapItemPicker 🗺️](https://github.com/lorenzofiamingo/swiftui-map-item-picker)\n\n[SwiftUI PhotosPicker 🌇](https://github.com/lorenzofiamingo/swiftui-photos-picker)\n\n[SwiftUI CachedAsyncImage 🗃️](https://github.com/lorenzofiamingo/swiftui-cached-async-image)\n\n[SwiftUI VerticalTabView 🔝](https://github.com/lorenzofiamingo/swiftui-vertical-tab-view)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenzofiamingo%2Fswiftui-shared-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Florenzofiamingo%2Fswiftui-shared-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Florenzofiamingo%2Fswiftui-shared-object/lists"}