{"id":892,"url":"https://github.com/vincent-pradeilles/weakable-self","last_synced_at":"2025-04-13T19:13:40.547Z","repository":{"id":54786719,"uuid":"151626389","full_name":"vincent-pradeilles/weakable-self","owner":"vincent-pradeilles","description":"A Swift micro-framework to easily deal with weak references to self inside closures","archived":false,"fork":false,"pushed_at":"2021-01-29T09:57:36.000Z","size":15,"stargazers_count":78,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-30T06:41:43.748Z","etag":null,"topics":["closures","ios","memory-management","swift","syntax"],"latest_commit_sha":null,"homepage":null,"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/vincent-pradeilles.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}},"created_at":"2018-10-04T19:39:11.000Z","updated_at":"2024-02-27T11:38:14.000Z","dependencies_parsed_at":"2022-08-14T03:00:19.527Z","dependency_job_id":null,"html_url":"https://github.com/vincent-pradeilles/weakable-self","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Fweakable-self","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Fweakable-self/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Fweakable-self/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Fweakable-self/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vincent-pradeilles","download_url":"https://codeload.github.com/vincent-pradeilles/weakable-self/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766748,"owners_count":21158301,"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":["closures","ios","memory-management","swift","syntax"],"created_at":"2024-01-05T20:15:34.049Z","updated_at":"2025-04-13T19:13:40.523Z","avatar_url":"https://github.com/vincent-pradeilles.png","language":"Swift","funding_links":[],"categories":["Code Quality","Libs","Utilities and Extensions","Utility [🔝](#readme)"],"sub_categories":["Utility","Getting Started"],"readme":"# WeakableSelf\n\n![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS-333333.svg)\n![pod](https://img.shields.io/cocoapods/v/WeakableSelf.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n## Context\n\nClosures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the reference of an external object, especially when this object is `self`.\n\nTo deal with this issue, developers are required to write additional code, using constructs such as `[weak self]` and `guard`, and the result looks like the following:\n\n```swift\nservice.call(completion: { [weak self] result in\n    guard let self = self else { return }\n    \n    // use weak non-optional `self` to handle `result`\n})\n```\n\n## Purpose of `WeakableSelf`\n\nThe purpose of this micro-framework is to provide the developer with a helper function `weakify` that will allow him to declaratively indicate that he wishes to use a weak non-optional reference to `self` in closure, and not worry about how this reference is provided.\n\n## Usage\n\nUsing this `weakify` function, the code above will be transformed into the much more concise:\n\n```swift\nimport WeakableSelf\n\nservice.call(completion: weakify { strongSelf, result in    \n    // use weak non-optional `strongSelf` to handle `result`\n})\n```\n\n`weakify` works with closures that take up to 7 arguments.\n\n## Installation\n\n### Requirements\n\n* Swift 4.2+\n* Xcode 10+\n\n### CocoaPods\n\nAdd the following to your `Podfile`:\n\n`pod \"WeakableSelf\"`\n\n### Carthage\n\nAdd the following to your `Cartfile`:\n\n`github \"vincent-pradeilles/weakable-self\"`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-pradeilles%2Fweakable-self","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvincent-pradeilles%2Fweakable-self","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-pradeilles%2Fweakable-self/lists"}