-
Notifications
You must be signed in to change notification settings - Fork 268
Propagating runtime arguments
Jasper Blues edited this page May 11, 2017
·
13 revisions
We can propagate a runtime argument through to a dependency as shown:
- (id)loyaltyManagementControllerWithLoyaltyAccounts:(NSArray *)loyaltyAccounts
{
return [TyphoonDefinition withClass:[LoyaltyManagementViewController class]
configuration:^(TyphoonDefinition* definition) {
[definition useInitializer:@selector(initWithLoyaltyClient:view:)
parameters:^(TyphoonMethod* initializer) {
[initializer injectParameterWith:[_networkComponents loyaltyClient]];
[initializer injectParameterWith:
[self loyaltyManagementViewWithAccounts:loyaltyAccounts]];
}];
}];
}
- (id)loyaltyManagementViewWithAccounts:(NSArray*)loyaltyAccounts
{
return [TyphoonDefinition withClass:[LoyaltyManagementView class]
configuration:^(TyphoonDefinition* definition) {
//The loyaltyAccounts parameter is propagated through the parent controller
// onto the view
[definition injectMethod:@selector(setLoyaltyAccounts:)
parameters:^(TyphoonMethod* method) {
[method injectParameterWith:loyaltyAccounts];
}];
}
Often, as is the case with a controller and a view's delegate we have a circular dependency. Circular dependencies are supported with run-time arguments. Here's an example:
- (id)loyaltyManagementControllerWithAccounts:(NSArray*)loyaltyAccounts
{
return [TyphoonDefinition withClass:[LoyaltyManagementViewController class] configuration:^(TyphoonDefinition* definition) {
[definition useInitializer:@selector(initWithLoyaltyClient:view:)
parameters:^(TyphoonMethod* initializer) {
[initializer injectParameterWith:[_networkComponents loyaltyClient]];
[initializer injectParameterWith:
[self loyaltyManagementViewWithAccounts:loyaltyAccounts]];
}];
}];
}
- (id)loyaltyManagementViewLoyaltyAccounts:(NSArray*)loyaltyAccounts
{
return [TyphoonDefinition withClass:[LoyaltyManagementView class]
configuration:^(TyphoonDefinition* definition) {
[definition injectProperty:@selector(delegate)
with:[self loyaltyManagementControllerWithAccounts:loyaltyAccounts]];
}];
}
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.