{"id":44716047,"url":"https://github.com/CaptureContext/swift-associated-objects","last_synced_at":"2026-02-28T02:01:03.370Z","repository":{"id":337078692,"uuid":"1027791998","full_name":"CaptureContext/swift-associated-objects","owner":"CaptureContext","description":"Associated objects utils","archived":false,"fork":false,"pushed_at":"2026-02-07T16:27:53.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-08T00:52:18.885Z","etag":null,"topics":["associatedobject","macro","macros","objc","runtime","swift-macros"],"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/CaptureContext.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-28T14:38:12.000Z","updated_at":"2026-02-07T16:27:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/CaptureContext/swift-associated-objects","commit_stats":null,"previous_names":["capturecontext/swift-associated-objects"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/CaptureContext/swift-associated-objects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-associated-objects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-associated-objects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-associated-objects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-associated-objects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptureContext","download_url":"https://codeload.github.com/CaptureContext/swift-associated-objects/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-associated-objects/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29922702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"online","status_checked_at":"2026-02-28T02:00:07.010Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["associatedobject","macro","macros","objc","runtime","swift-macros"],"created_at":"2026-02-15T14:00:35.387Z","updated_at":"2026-02-28T02:01:03.363Z","avatar_url":"https://github.com/CaptureContext.png","language":"Swift","readme":"# swift-associated-objects\n\n[![CI](https://github.com/capturecontext/swift-associated-objects/actions/workflows/ci.yml/badge.svg)](https://github.com/capturecontext/swift-associated-objects/actions/workflows/ci.yml) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcapturecontext%2Fswift-associated-objects%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/capturecontext/swift-associated-objects) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcapturecontext%2Fswift-associated-objects%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/capturecontext/swift-associated-objects)\n\nAssociated objects utils\n\n## Table of contents\n\n- [Documentation](https://swiftpackageindex.com/CaptureContext/swift-associated-objects/0.5.0/documentation/associatedobjects)\n- [Usage](#usage)\n- [Installation](#installation)\n  - [Basic](#basic)\n  - [Recommended](#recommended)\n- [Licence](#licence)\n\n## Usage\n\nBasic helpers for object association are available in \"AssociatedObjects\" product\n\n```swift\nextension UIViewController {\n  var someStoredProperty: Int {\n    get { getAssociatedObject(forKey: #function).or(0) }\n    set { setAssociatedObject(newValue, forKey: #function)  }\n  }\n}\n\nlet value: Bool = getAssociatedObject(forKey: \"value\", from: object)\n```\n\nBut the full power of associated objects is provided by `AssociatedObjectsMacros` target\n\n\u003e By default `@AssociatedObject` macro uses `.retain(.nonatomic)` for classes and `.copy(.nonatomic)` `objc_AssociationPolicy` for structs.\n\n```swift\nimport AssociatedObjectsMacros\n\nextension SomeClass {\n  @AssociatedObject\n  var storedVariableInExtension: Int = 0\n  \n  @AssociatedObject(readonly: true)\n  var storedVariableInExtension: SomeObject = .init()\n  \n  @AssociatedObject\n  var optionalValue: Int?\n  \n  @AssociatedObject\n  var object: Int?\n    \n  @AssociatedObject(threadSafety: .atomic)\n  var threadSafeValue: Int?\n    \n  @AssociatedObject(threadSafety: .atomic)\n  var threadSafeObject: Object?\n    \n  @AssociatedObject(policy: .assign)\n  var customPolicyValue: Int?\n    \n  @AssociatedObject(policy: .retain(.atomic))\n  var customPolicyThreadSafeObject: Object?\n}\n```\n\n\u003e Macros require swift-syntax compilation, so it will affect cold compilation time\n\n## Installation\n\n### Basic\n\nYou can add AssociatedObjects to an Xcode project by adding it as a package dependency.\n\n1. From the **File** menu, select **Swift Packages › Add Package Dependency…**\n2. Enter [`\"https://github.com/capturecontext/swift-associated-objects.git\"`](https://github.com/capturecontext/swift-associated-objects.git) into the package repository URL text field\n3. Choose products you need to link them to your project.\n\n### Recommended\n\nIf you use SwiftPM for your project, you can add AssociatedObjects to your package file.\n\n```swift\n.package(\n  url: \"https://github.com/capturecontext/swift-associated-objects.git\", \n  .upToNextMinor(from: \"0.1.4\")\n)\n```\n\nDo not forget about target dependencies:\n\n```swift\n.product(\n  name: \"AssociatedObjects\", \n  package: \"swift-associated-objects\"\n)\n```\n\n```swift\n.product(\n  name: \"AssociatedObjectsMacros\", \n  package: \"swift-associated-objects\"\n)\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e _The package is compatible with non-Apple platforms, but this package uses conditional compilation, so APIs are only available `#if canImport(ObjectiveC)`_\n\n## License\n\nThis library is released under the MIT license. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCaptureContext%2Fswift-associated-objects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCaptureContext%2Fswift-associated-objects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCaptureContext%2Fswift-associated-objects/lists"}