• Stars
    star
    117
  • Rank 295,094 (Top 6 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

swift-tips

A collection useful tips for the Swift language
Swift
979
star
2

KeyPathKit

KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.
Swift
420
star
3

weakable-self

A Swift micro-framework to easily deal with weak references to self inside closures
Swift
78
star
4

KeyPathTesting

A Swift framework that defines a KeyPath-based syntax for writing unit tests
Swift
71
star
5

AutoMocker

AutoMocker is a Swift framework that leverages the type system to let you easily create mocked instances of your data types.
Swift
43
star
6

slides

37
star
7

ios-memes

31
star
8

learning-swiftui-when-you-already-know-uikit

Learning SwiftUI, when you already know UIKit
Swift
19
star
9

live-ios-app-architecture

18
star
10

kotlin-tips

A collection useful tips for the Kotlin language
Kotlin
13
star
11

live-async-await-ios13

Swift
11
star
12

workshop-nsspain-2019

Leveraging KeyPaths to their full potential
Swift
10
star
13

live-async-algorithms

9
star
14

NSAttributedStringBuilder

A micro-framework that exposes a function builder to compose attributed strings
Swift
8
star
15

how-to-master-combine-like-a-pro

Swift
8
star
16

euler-kotlin

Standard mathematical operations implemented through type extensions and infix functions
Kotlin
7
star
17

swift-playgrounds-background-remover-app

This is the repository with the code for this livestream 👉 https://www.youtube.com/watch?v=gLn_0nan-pw
Swift
5
star
18

experimenting-with-createml-resources

Swift
3
star
19

live-building-your-first-swiftui-app

Swift
3
star
20

learning-uikit-when-you-already-know-swiftui

Swift
3
star
21

swift-island-2023

Swift
2
star
22

how-to-master-modern-swift-syntaxes-keypath

Swift
2
star
23

parallelize-blocking-api

Swift
2
star
24

live-discovering-swift-macros

Swift
1
star
25

swift-playgrounds

Swift
1
star
26

LocaLint

A command-line tool to lint the usage of iOS localized Strings
Swift
1
star
27

reflexive-factory

Swift
1
star
28

live-discovering-swift-data

Swift
1
star
29

loader-table-view

Swift
1
star
30

how-to-get-started-with-swift-macros

How to get started with Swift Macros
Swift
1
star
31

from-async-rx-api

Swift
1
star
32

vincent-pradeilles.github.io

CSS
1
star