Recommended IoC framework for iOS? [closed]

2019-01-31 20:40发布

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?

3条回答
霸刀☆藐视天下
2楼-- · 2019-01-31 20:57

Well, I hope you forgive me a little plug here, but I just released my own DI framework for Objective-C: Syringe

https://github.com/tomekc/Syringe

It is simplistic and lightweight on purpose, my primary goal was to make it as not obtrusive as possible. I have a strong Java background, so I designed it after Google Guice and Spring.

查看更多
祖国的老花朵
3楼-- · 2019-01-31 20:59

...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.

查看更多
趁早两清
4楼-- · 2019-01-31 21:07

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

查看更多
登录 后发表回答