Can anyone recommend a good IoC framework for iOS to facilitate dependency injection?
The only one I've found so far is Objection Framework which apparently is similar to Guice (which unfortunately is unfamiliar to me). Is this one a common choice for iOS and are there competing frameworks that are worth checking out?
You can waste days evaluating IOC containers. The top ones are quite similar. There is not much in this, but the best ones are StructureMap and AutoFac.
The most valuable benefit of using an IoC container is that you can have a configuration switch in one place which lets you change between, say, test mode and production mode. For example, suppose you have two versions of your database access classes...
A great example of an implementation of IoC is Spring Framework. The Spring container instantiates and manages the lifecycle of the objects that are a part of the program. The user in the configuration file provides the information related to what objects and dependencies are required by the application.
Swinject is a lightweight dependency injection framework for Swift. Dependency injection (DI) is a software design pattern that implements Inversion of Control (IoC) for resolving dependencies.
Typhoon
The Typhoon-website lists the key features. A quick summary:
Non-invasive. No macros or XML required. Configuration is done using an Objective-C or Swift API that takes advantage of the Objective-C runtime.
Lightweight. Just 2500 lines of code. It has a very low footprint, so is appropriate for CPU and memory constrained devices. Tuned for performance.
Makes it easy to have multiple configurations of the same base-class or protocol.
No magic strings - supports IDE refactoring, code-completion and compile-time checking.
Supports injection of view controllers and storyboard integration.
Supports both initializer and property injection, plus life-cycle management.
Powerful memory management features. Provides pre-configured objects, without the memory overhead of singletons.
Excellent support for circular dependencies.
Battle-tested - used in all kinds of Appstore-featured apps.
An internationally distributed core team (we even monitor StackOverflow), so support for any of your questions are never far away :)
API Docs and sample app
...are there competing frameworks that are worth checking out?
Objection is the DI library I could find on google for iOS, so you might be stuck with it if you want a pre-built library.
DI doesn't specifically require a framework to use. If your app is small, you can simply create all your instances at the application root and inject by hand.
If you need more than this, and the existing frameworks aren't cutting it for you, you could roll your own Service Locator, then build a DI container on top of it.
You could also port an existing smaller framework from another platform. There are several "small" ones on .Net, for example - Ninject and SimpleInjector.
Is this one a common choice for iOS...?
It seems that it is a fairly small project as there is only one author/contributor listed. There aren't many issues filed. The iOS market is fairly large though. So I'm thinking that only a very small portion of all iOS developers use this library.
But this isn't necessarily a bad thing. It seems to be created, used, and supported by a small company. It has had fairly steady updates for the past year.
My anecdotal experience with similarly scoped open source projects: I don't always get new features super-often, and I'm often the one who ends up finding bugs. But I tend to get support on the existing feature set very quickly, and a lot of attention is paid to support e-mails I've sent. YMMV.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With