{"id":15561252,"url":"https://github.com/bellapplab/weakable","last_synced_at":"2026-04-20T03:03:36.403Z","repository":{"id":56927349,"uuid":"140672279","full_name":"BellAppLab/Weakable","owner":"BellAppLab","description":"An easy way to hold weak references in Swift.","archived":false,"fork":false,"pushed_at":"2025-09-30T08:45:51.000Z","size":124,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-16T07:28:39.255Z","etag":null,"topics":["carthage","cocoapods","ios","linux","macos","osx","swift","swift-package-manager","tvos","watchos","weak"],"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/BellAppLab.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":"2018-07-12T06:42:08.000Z","updated_at":"2025-09-30T08:45:55.000Z","dependencies_parsed_at":"2025-09-30T10:18:11.593Z","dependency_job_id":"857461a4-c70f-4b18-997a-8b3b268f19ca","html_url":"https://github.com/BellAppLab/Weakable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/BellAppLab/Weakable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FWeakable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FWeakable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FWeakable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FWeakable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BellAppLab","download_url":"https://codeload.github.com/BellAppLab/Weakable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BellAppLab%2FWeakable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32031070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"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":["carthage","cocoapods","ios","linux","macos","osx","swift","swift-package-manager","tvos","watchos","weak"],"created_at":"2024-10-02T16:06:46.527Z","updated_at":"2026-04-20T03:03:36.336Z","avatar_url":"https://github.com/BellAppLab.png","language":"Swift","readme":"# Weakable [![Version](https://img.shields.io/badge/Version-2.0.0-black.svg?style=flat)](#installation) [![License](https://img.shields.io/cocoapods/l/Weakable.svg?style=flat)](#license)\n\n[![Platforms](https://img.shields.io/badge/Platforms-iOS|watchOS|tvOS|macOS|Linux-brightgreen.svg?style=flat)](#installation)\n[![Swift support](https://img.shields.io/badge/Swift-4.x%20%7C%205.x%20%7C%206.0-red.svg?style=flat)](#swift-versions-support)\n[![Swift Package Manager compatible](https://img.shields.io/badge/SPM-compatible-orange.svg?style=flat)](https://github.com/apple/swift-package-manager)\n\n![Weakable](./Images/weakable.png)\n\nWeakable is an easy way to hold `weak` references in Swift.\n\nWith Weakable you can create weak arrays, weak dictionaries and many other cool things.\n\n😎\n\n## Requirements\n\n* iOS 12+\n* watchOS 4+\n* tvOS 12+\n* macOS 11+\n* Swift 4+\n\n## Usage\n\nDeclare your `Weak` variable in one of the two ways provided:\n\n```swift\n//Given a class\nclass TestClass {}\n//and an instance of that class\nvar aTestObject = TestClass()\n\n//You can create a Weak like this:\nvar weakTestObject = Weak(aTestObject)\n\n//Or using the shorthand operator ≈\nvar anotherWeakTestObject = ≈test\n```\n\nAccess your variable:\n\n```swift\nweakTestObject.object //returns your value as an optional, since it may or may not have been released\n```\n\n## Operators\n\n`Weakable` comes with 3 operators, all using the `≈` character (**⌥ + x**).\n\n* `prefix ≈`\n  * Shorthand contructor for a `Weak` variable:\n\n```swift\n//Given an object\nlet object = AwesomeClass()\n\n//you can create a Weak by either\nvar weakObject = Weak(object)\n\n//or\nvar weakObject = ≈object\n```\n\n* `postfix operator ≈`\n  * Shorthand accessor for `Weak`:\n  \n```swift\n//Given a Weak\nvar weakObject = ≈object\n\n//you can access the underlying object by\nweakObject.object\n\n//or\nweakObject≈\n```\n\n* `infix operator ≈`\n  * Shorthand assignment for `Weak`:\n  \n```swift\n//Given a Weak\nvar weakObject = ≈object\n\n//you can change the underlying object by\nweakObject.object = anotherObject\n\n//or\nweakObject ≈ anotherObject\n```\n    \n## Arrays and Dictionaries\n\nYou can safely store your `Weak` variables in collections (eg. `[Weak\u003cTestClass\u003e]`). The underlaying objects won't be retained.\n\n```swift\nvar tests = (1...10).map { TestClass() } // 10 elements\nvar weakTests = ≈tests // 10 elements\n\ntests.removeLast() // `tests` now have 9 elements, but `weakTests` have 10\n\nweakTests = weakTests.filterWeaks() // `weakTests` now have 9 elements too, since we dropped the released objects from it\n```\n\nYou can also quickly \"unwrap\" the elements in a `Weak` collection:\n\n```swift\nlet tests = weakTests.compactWeaks()\n```\n\nThe variable `tests` will now be a `[TestClass]` containing only the elements that haven't been released yet.\n\n## Global weaks\n\nVersion `2.0` introduces the concept of global weak variables. Say you want to share the same instance of a class in several places, but you want to release the global variable once all other references are destroyed. That's what a global weak is.\n\n```swift\nfinal class TestClass: WeaklyGloballyIdentifiable {\n    typealias GlobalID = Int\n\n    @WeakGlobalActor\n    static var weakGlobals: [GlobalID: Weak\u003cTestClass\u003e] = [:]\n}\n\nlet firstInstance = TestClass.weakGlobal(id: 1, default: TestClass())\nlet secondInstance = TestClass.weakGlobal(id: 1, default: TestClass())\n\nprint(firstInstance === secondInstance) // `true`\n```\n\n## Installation\n\n### Swift Package Manager\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/BellAppLab/Weakable\", from: \"2.0\")\n]\n```\n\nThen `import Weakable` where needed.\n\n### Legacy\n\nThe following import methods only work for version `1.0.1`. \n\n#### Cocoapods\n\n```ruby\npod 'Weakable', '~\u003e 1.0'\n```\n\nThen `import Weakable` where needed.\n\n#### Carthage\n\n```swift\ngithub \"BellAppLab/Weakable\" ~\u003e 1.0\n```\n\nThen `import Weakable` where needed.\n\n#### Git Submodules\n\n```\ncd toYourProjectsFolder\ngit submodule add -b submodule --name Weakable https://github.com/BellAppLab/Weakable.git\n```\n\nThen drag the `Weakable` folder into your Xcode project.\n\n## Author\n\nBell App Lab, apps@bellapplab.com\n\n### Credits\n\n[Logo image](https://thenounproject.com/search/?q=weak\u0026i=37722#) by [Артур Абт](https://thenounproject.com/Abt) from [The Noun Project](https://thenounproject.com/)\n\n## License\n\nWeakable is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Fweakable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbellapplab%2Fweakable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbellapplab%2Fweakable/lists"}