Skip to content

Commit

Permalink
Merge pull request #350 from chazmuzz/master
Browse files Browse the repository at this point in the history
Inject dependencies into storyboard views that have a typhoonKey
  • Loading branch information
jasperblues committed May 27, 2015
2 parents 8472b71 + 4ff6db4 commit 81db968
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Source/ios/Storyboard/TyphoonStoryboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ - (NSString *)typhoonKey

@end

//-------------------------------------------------------------------------------------------
#pragma mark - UIView + TyphoonDefinitionKey

@interface UIView (TyphoonDefinitionKey)

@property(nonatomic, strong) NSString *typhoonKey;

@end

@implementation UIView (TyphoonDefinitionKey)

static const char *kTyphoonKey;

- (void)setTyphoonKey:(NSString *)typhoonKey
{
objc_setAssociatedObject(self, &kTyphoonKey, typhoonKey, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSString *)typhoonKey
{
return objc_getAssociatedObject(self, &kTyphoonKey);
}

@end

//-------------------------------------------------------------------------------------------
#pragma mark - TyphoonStoryboard

Expand Down Expand Up @@ -80,6 +105,23 @@ - (void)injectPropertiesForViewController:(UIViewController *)viewController
for (UIViewController *controller in viewController.childViewControllers) {
[self injectPropertiesForViewController:controller];
}

[self injectPropertiesInView:viewController.view];
}

- (void)injectPropertiesInView:(UIView *)view
{
if (view.typhoonKey.length > 0) {
[self.factory inject:view withSelector:NSSelectorFromString(view.typhoonKey)];
}

if ([view.subviews count] == 0) {
return;
}

for (UIView *subview in view.subviews) {
[self injectPropertiesInView:subview];
}
}

@end

0 comments on commit 81db968

Please sign in to comment.