Locatable alternatives and similar libraries
Based on the "Dependency Injection" category.
Alternatively, view Locatable alternatives based on common mentions on social networks and blogs.
-
Pilgrim
Dependency injection for Swift (iOS, OSX, Linux). Strongly typed, pure Swift successor to Typhoon. -
ViperServices
Simple dependency injection container for services written for iOS in swift supporting boot order
SaaSHub - Software Alternatives and Reviews
Do you think we are missing an alternative of Locatable or a related project?
Popular Comparisons
README
Locatable
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:
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:
// leverages @autoclosure
Locator.register(Servicing.self, Service())
// leverages default argument values
Locator.register { return Service() as Servicing }
Service locating supports two distinct semantics:
// 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