-
Notifications
You must be signed in to change notification settings - Fork 268
Auto injection (Objective C)
With a strong foundation, Typhoon is capable of performing [all kinds of injections](types of injections). This power and flexibility is invariably needed at some point. Often, however, all that's required is simple property injection. In these cases, auto-wiring can save time.
Use Typhoon auto-injection to:
- Quickly perform property injection of classes or protocols, matching by type.
- Avoid having to register a definition in an assembly (this is nice with Storyboards)
###Import the TyphoonAutoInjection header
//This is also included in the umbrella Typhoon.h
#import "TyphoonAutoInjection.h"
###Auto-injecting Protocols
@interface CollectOffersController : UIViewController
@property(nonatomic, strong) InjectedProtocol(ImageProvider) imageProvider;
@end
Note that we do not include the id type or brackets, (ie id <ImageProvider>
) in the protocol name. This is implied.
###Auto-injecting Classes
@interface ChannelBrowserController : UIViewController
@property (nonatomic, strong) InjectedClass(HttpWebService) webService;
@end
Note that we do not include '*' character (ie HttpWebService *service). This is implied.
##Use Auto-injection . . .
- When you'd like to save time.
- When you'd like to document a classes dependency information in its header file.
##Don't use Auto-injection . .
- When you wish to avoid coupling your class to any Typhoon APIs. Define injections in a
TyphoonAssembly
instead. - When you wish to document an applications assembly in a centralized fashion.
NB: If you wish you can mix auto-wiring and along with a definition in the assembly. All of the auto-wiring injections will be applied along with ones defined in the assembly definition. When duplication occurs the manual rules defined in the assembly win.
Something still not clear? How about posting a question on StackOverflow.
Get started in two minutes.
Get familiar with Typhoon.
- Types of Injections
- What can be Injected
- Auto-injection (Objective-C)
- Scopes
- Storyboards
- TyphoonLoadedView
- Activating Assemblies
Become a Typhoon expert.
For contributors or curious folks.