The key to dependency injection is protocols. From there sprouts many variations, flavours, and techniques. Although this is yet another dependency injection™ blog post, I would like to share a pure Swift, battle-tested DI implementation with no outside dependencies or magic. It combines protocol extension and type erasure to give you a solid, flexible dependency injection.
Thin AppDelegate with Pluggable Services
Many techniques have been tried to tame the AppDelegate beast, usually ending up in moving code into private functions or extensions. However, the AppDelegate is much more complex than just moving code around. In this post, let’s examine a pluggable service technique with a few bonuses at the end.
Protocol-Oriented Routing in Swift
There are hundreds of complex routing frameworks and libraries in iOS. Usually they’re overly complex to retrofit into an existing app or they completely bypass Storyboards. In this post, I’d like to offer a simple, native-like routing mechanism that leverages Storyboards like a boss to handle navigation.
Swifty Localization with Xcode Support
Localization in Xcode is handled with NSLocalizedString, but it is such a verbose and legacy-like API. There’s a Swiftier way that still respects Xcode .xliff exports and comments.
Swifty Locations with Observables
Let’s use the closure-based pattern to wrap CLLocationManager for allowing callers to subscribe to observables instead of using shared delegate functions.
Delegates to Swift Closure Pattern
Delegation is a simple and powerful pattern. However, closures are more Swifty and scales better. Let’s convert delegates to closures!