Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vincent-pradeilles/locatable
A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern
https://github.com/vincent-pradeilles/locatable
Last synced: 3 days ago
JSON representation
A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern
- Host: GitHub
- URL: https://github.com/vincent-pradeilles/locatable
- Owner: vincent-pradeilles
- License: mit
- Created: 2019-06-07T00:05:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-02T14:50:05.000Z (over 3 years ago)
- Last Synced: 2024-11-26T15:02:47.293Z (16 days ago)
- Language: Swift
- Homepage:
- Size: 30.3 KB
- Stars: 118
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swift - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Libs / Dependency Injection)
- awesome-swift - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Libs / Dependency Injection)
- awesome-ios-star - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Dependency Injection / Getting Started)
- fucking-awesome-swift - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Libs / Dependency Injection)
- awesome-ios - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Dependency Injection / Getting Started)
- fucking-awesome-ios - Locatable - A micro-framework that leverages Property Wrappers to implement the Service Locator pattern. (Dependency Injection / Getting Started)
- awesome-swift - Locatable - A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern ` 📝 2 years ago ` (Dependency Injection [🔝](#readme))
README
# Locatable
![platforms](https://img.shields.io/badge/platforms-iOS-333333.svg)
![pod](https://img.shields.io/cocoapods/v/Locatable.svg)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)## Context
Locatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom attribute `@Locatable`.
Here's an example of how it can be used:
```swift
protocol Servicing {
func action()
}class Service: Servicing {
func action() {
print("I'm performing a service 😊")
}
}Locator.register(Servicing.self, { return Service() })
class MyController {
@Locatable(.sharedInstance) var service: Servicing
func work() {
self.service.action()
}
}let controller = MyController()
controller.work() // I'm performing a service 😊
```For convenience, some shorthand syntax are also available:
```swift
// leverages @autoclosure
Locator.register(Servicing.self, Service())// leverages default argument values
Locator.register { return Service() as Servicing }
```Service locating supports two distinct semantics:
```swift
// Will return an instance that is shared across the app
Locatable(.sharedInstance) var service: Servicing// Will return a new instance every time
Locatable(.newInstance) var service: Servicing
```## Requirements
Xcode 11+ & Swift 5.1
## Installation
### CocoaPods
Add the following to your `Podfile`:
`pod "Locatable"`
### Carthage
Add the following to your `Cartfile`:
`github "vincent-pradeilles/locatable"`
## Author
* Twitter: [@v_pradeilles](https://twitter.com/v_pradeilles)