A micro-framework that leverages Swift Property Wrappers to implement the Service Locator pattern

Related tags

Animation locatable
Overview

Locatable

platforms pod Carthage compatible

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

You might also like...
WWDC 2019'da tanıtılan yeni UI framework'ü SwiftUI'ya giriş amacı gütmektedir.

SwiftUI-Presentation Burada SwiftUI'yı Türkçe bir şekilde sunmak istiyorum. Playground'u açtıktan sonra Editor - Show Rendered Markup seçeneği ile bi

Design-system-demo - This example code is bare-bones to show you what this framework can do

Basic Style Dictionary This example code is bare-bones to show you what this fra

A framework and generator for displaying SwiftUI component libraries

Exhibition Exhibition is a framework and generator for displaying a SwiftUI component library. Inspired by Storybook and Showkase Installation Swift P

Framework to help you better manage UITableViews
Framework to help you better manage UITableViews

UITableView made simple 🙌 Main Features 🙉 Skip the UITableViewDataSource & UITableViewDelegate boilerplate and get right to building your UITableVie

iOS framework for impressive transition animations between views.

CoreTransition iOS framework for impressive transition animations between views. Built using Swift, and supports a lot of animations to navigate to a

☄️Comets: Animating Particles in Swift
☄️Comets: Animating Particles in Swift

Comets ☄️ Comets: Animating Particles in Swift animation made by kevin as part of Voicy design implements Bennet van der Linden medium Comets: Animati

A DSL to make animation easy on iOS with Swift.
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Elegant SVG animation kit for swift
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

Comments
  • Use auto closure and inferred type

    Use auto closure and inferred type

    On my phone so not ideal to make the PR myself but you should change to this:

    static func register<T>(_ type: T.Type = T.self, _ factory: @autoclosure @escaping () -> T) {
    

    This would allow the call site to either choose to use the autoclosure feature:

    Resolver.register( Servicing.self, Service() )
    

    Or to use the = T.self and inference and be able to write:

    Resolver.register { Service() as Servicing }
    
    opened by AliSoftware 1
  • Fixed a compilation error in 'Locatable'

    Fixed a compilation error in 'Locatable'

    Fixed a Swift 5 compilation error in 'Locatable' which was complaining of wrapper type 'Locatable' missing a non-static property named 'wrappedValue'. Renaming the Locatable.value property to Locatable.wrappedValue fixes it.

    opened by adil-hussain-84 0
Owner
Vincent Pradeilles
French iOS software engineer, working in Lyon, France 🇫🇷
Vincent Pradeilles
Emil 3 Jan 31, 2022
LottieUI - A library developed to make Lottie easy to implement. It supports iOS and macOS

LottieUI It is a library developed to make Lottie easy to implement. It supports

jasu 51 Dec 24, 2022
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.

TopicEventBus Publish–subscribe design pattern implementation framework, with ability to publish events by topic. (NotificationCenter extended alterna

Matan Abravanel 55 Nov 29, 2021
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Shohei Yokoyama 3k Dec 27, 2022
SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift.

SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift ?? Demo There are 5 types of animation for component. border borde

Shohei Yokoyama 126 Oct 28, 2021
Testing the new ShazamKit framework announced at WWDC 2021

ShazamKit Demo Using the ShazamKit framework announced at WWDC 2021 to perform song recognition. Demo Tweet Usage Open the project and change the Bund

Sai Kambampati 18 Mar 17, 2022
Facebook's Pop Framework, By Examples

Facebook's Pop Framework, By Examples --- This project is a tutorial (Check tutorial here) for how to use Pop framework by Facebook. Its very easy and

Hossam Ghareeb 183 Aug 1, 2022
Simple, extensible interpolation framework

THIS PROJECT IS NO LONGER MAINTAINED. Popsicle is a Swift framework for creating and managing interpolations of different value types with built-in UI

David Roman 1.1k Nov 17, 2022