diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h index 02487e0..de0f25f 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h @@ -10,10 +10,16 @@ @interface MVMCoreViewControllerProgrammaticMappingObject : NSObject -// View Controller Class, for loading by class. +/// View Controller Class, for loading by class. @property (nonnull, strong, nonatomic) Class viewControllerClass; -// Initializes with the given class. +/// Configuration block executed on creation of the controller before loading. +@property (nullable, copy, nonatomic) void (^configureHandler)(UIViewController * _Nonnull); + +/// Initializes with the given class. - (nullable id)initWithClass:(nonnull Class)viewControllerClass; +/// Initializes with the given class. Assigns a configuration block triggered on intiailization which allows additional configuration of the view controller before its loaded, i.e. injecting top level dependencies. +- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^_Nonnull)(UIViewController * _Nonnull))configureBlock; + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m index 8547285..a47a583 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m @@ -19,8 +19,20 @@ return self; } +- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^)(UIViewController * _Nonnull))configureBlock { + self = [self initWithClass:viewControllerClass]; + if (self) { + self.configureHandler = configureBlock; + } + return self; +} + - (nullable UIViewController *)createViewController { - return [[self.viewControllerClass alloc] init]; + UIViewController *newController = [[self.viewControllerClass alloc] init]; + if (self.configureHandler) { + self.configureHandler(newController); + } + return newController; } @end