{"id":3225,"url":"https://github.com/vincent-pradeilles/locatable","last_synced_at":"2025-04-13T19:13:31.967Z","repository":{"id":53173486,"uuid":"190665810","full_name":"vincent-pradeilles/locatable","owner":"vincent-pradeilles","description":"A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern","archived":false,"fork":false,"pushed_at":"2021-04-02T14:50:05.000Z","size":31,"stargazers_count":118,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T19:55:08.078Z","etag":null,"topics":[],"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/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":"2019-06-07T00:05:05.000Z","updated_at":"2024-10-13T19:59:16.000Z","dependencies_parsed_at":"2022-09-14T09:42:23.269Z","dependency_job_id":null,"html_url":"https://github.com/vincent-pradeilles/locatable","commit_stats":null,"previous_names":["vincent-pradeilles/injectable"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Flocatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Flocatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Flocatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent-pradeilles%2Flocatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vincent-pradeilles","download_url":"https://codeload.github.com/vincent-pradeilles/locatable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248766747,"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":[],"created_at":"2024-01-05T20:16:35.006Z","updated_at":"2025-04-13T19:13:31.929Z","avatar_url":"https://github.com/vincent-pradeilles.png","language":"Swift","funding_links":[],"categories":["Libs","Dependency Injection","Dependency Injection [🔝](#readme)"],"sub_categories":["Dependency Injection","Getting Started","Web View"],"readme":"# Locatable\n\n![platforms](https://img.shields.io/badge/platforms-iOS-333333.svg)\n![pod](https://img.shields.io/cocoapods/v/Locatable.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n## Context\n\nLocatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom attribute `@Locatable`.\n\nHere's an example of how it can be used:\n\n```swift\nprotocol Servicing {\n    func action()\n}\n\nclass Service: Servicing {\n    func action() {\n        print(\"I'm performing a service 😊\")\n    }\n}\n\nLocator.register(Servicing.self, { return Service() })\n\nclass MyController {\n    @Locatable(.sharedInstance) var service: Servicing\n    \n    func work() {\n        self.service.action()\n    }\n}\n\nlet controller = MyController()\n\ncontroller.work() // I'm performing a service 😊\n```\n\nFor convenience, some shorthand syntax are also available:\n\n```swift\n// leverages @autoclosure\nLocator.register(Servicing.self, Service())\n\n// leverages default argument values\nLocator.register { return Service() as Servicing }\n```\n\nService locating supports two distinct semantics:\n\n```swift\n// Will return an instance that is shared across the app\nLocatable(.sharedInstance) var service: Servicing\n\n// Will return a new instance every time\nLocatable(.newInstance) var service: Servicing\n```\n\n## Requirements\n\nXcode 11+ \u0026 Swift 5.1\n\n## Installation\n\n### CocoaPods\n\nAdd the following to your `Podfile`:\n\n`pod \"Locatable\"`\n\n### Carthage\n\nAdd the following to your `Cartfile`:\n\n`github \"vincent-pradeilles/locatable\"`\n\n## Author\n\n* Twitter: [@v_pradeilles](https://twitter.com/v_pradeilles)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-pradeilles%2Flocatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvincent-pradeilles%2Flocatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent-pradeilles%2Flocatable/lists"}