TyphoonDefinition

Objective-C

@interface TyphoonDefinition : NSObject <NSCopying> {
  Class _type;
  NSString *_key;
  TyphoonMethod *_initializer;
  TyphoonMethod *_beforeInjections;
  NSMutableSet *_injectedProperties;
  NSMutableSet *_injectedMethods;
  TyphoonMethod *_afterInjections;
  TyphoonScope _scope;
  TyphoonDefinition *_parent;
}

Swift

class TyphoonDefinition : NSObject, NSCopying

@ingroup Definition

  • Undocumented

    Declaration

    Objective-C

    Class _type
  • Undocumented

    Declaration

    Objective-C

    NSString *_key
  • Undocumented

    Declaration

    Objective-C

    TyphoonMethod *_initializer
  • Undocumented

    Declaration

    Objective-C

    TyphoonMethod *_beforeInjections
  • Undocumented

    Declaration

    Objective-C

    NSMutableSet *_injectedProperties
  • Undocumented

    Declaration

    Objective-C

    NSMutableSet *_injectedMethods
  • Undocumented

    Declaration

    Objective-C

    TyphoonMethod *_afterInjections
  • Undocumented

    Declaration

    Objective-C

    TyphoonScope _scope
  • Undocumented

    Declaration

    Objective-C

    TyphoonDefinition *_parent
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, readonly) Class type

    Swift

    var type: AnyClass! { get }
  • A custom callback methods that is invoked before properties and method injection occurs.

    Declaration

    Objective-C

    - (void)performBeforeInjections:(SEL)sel;

    Swift

    func perform(beforeInjections sel: Selector!)
  • Undocumented

    Declaration

    Objective-C

    - (void)performBeforeInjections:(SEL)sel parameters:(void(^)(TyphoonMethod *params))parametersBlock;

    Swift

    func perform(beforeInjections sel: Selector!, parameters parametersBlock: ((TyphoonMethod?) -> Void)!)
  • A custom callback methods that is invoked after properties and method injection occurs.

    Declaration

    Objective-C

    - (void)performAfterInjections:(SEL)sel;

    Swift

    func perform(afterInjections sel: Selector!)
  • Undocumented

    Declaration

    Objective-C

    - (void)performAfterInjections:(SEL)sel parameters:(void(^)(TyphoonMethod *param))parameterBlock;

    Swift

    func perform(afterInjections sel: Selector!, parameters parameterBlock: ((TyphoonMethod?) -> Void)!)
  • The scope of the component, default being TyphoonScopeObjectGraph.

    Declaration

    Objective-C

    @property (nonatomic) TyphoonScope scope;

    Swift

    var scope: TyphoonScope { get set }
  • Specifies visibility for for AutoInjection.

    AutoInjection performs when using method:

    • (void)injectProperty:(SEL)withSelector; or when using: InjectedClass or InjectedProtocol marco

    Declaration

    Objective-C

    @property (nonatomic) TyphoonAutoInjectVisibility autoInjectionVisibility;

    Swift

    var autoInjectionVisibility: TyphoonAutoInjectVisibility { get set }
    • A parent component. When parent is defined the initializer and/or properties from a definition are inherited, unless overridden. Example: * “`
    • (id)signUpClient { return [TyphoonDefinition withClass:[SignUpClientDefaultImpl class] configuration:^(TyphoonDefinition* definition) { definition.parent = [self abstractClient]; }]; }

    • (id)abstractClient { return [TyphoonDefinition withClass:[ClientBase class] configuration:^(TyphoonDefinition* definition) { [definition injectProperty:@selector(serviceUrl) with:TyphoonConfig(@"service.url”]; [definition injectProperty:@selector(networkMonitor) with:[self internetMonitor]]; [definition injectProperty:@selector(allowInvalidSSLCertificates) with:@(YES)]; }]; }

    *
    * - see: abstract
    *
    

    Declaration

    Objective-C

    @property (nonatomic, strong) id parent;

    Swift

    var parent: Any! { get set }
  • If set, designates that a component can not be instantiated directly.

    See

    parent

    Declaration

    Objective-C

    @property (nonatomic) BOOL abstract;

    Swift

    var abstract: Bool { get set }

Factory methods

  • Undocumented

    Declaration

    Objective-C

    + (id)withClass:(Class)clazz;

    Swift

    class func withClass(_ clazz: AnyClass!) -> Any!
  • Undocumented

    Declaration

    Objective-C

    + (id)withClass:(Class)clazz configuration:(TyphoonDefinitionBlock)injections;

    Swift

    class func withClass(_ clazz: AnyClass!, configuration injections: TyphoonDefinitionBlock!) -> Any!
    • A component that will produce an instance (with or without parameters) of this component. For example: * “`
    • (id)sqliteManager { return [TyphoonDefinition withClass:[MySqliteManager class] configuration:^(TyphoonDefinition* definition) { [definition useInitializer:@selector(initWithDatabaseName:) parameters:^(TyphoonMethod* initializer) { [initializer injectParameterWith:@"database.sqlite”]; }]; definition.scope = TyphoonScopeSingleton; }]; }

    • (id)databaseQueue { return [TyphoonDefinition withClass:[FMDatabaseQueue class] configuration:^(TyphoonDefinition* definition) { [definition useInitializer:@selector(queue)]; definition.factory = [self sqliteManager]; }]; }

    *
    * - note: If the factory method takes arguments, these are provided in the initializer block, just like a regular initializer method.
    *
    * - see: injectProperty:withDefinition:selector: An alternative short-hand approach for no-args instances.
    * - see: injectProperty:withDefinition:keyPath: An alternative short-hand approach for no-args instances.
    * - see: TyphoonFactoryProvider - For creating factories where the configuration arguments are not known until runtime.
    *
    *
    

    Declaration

    Objective-C

    + (id)withFactory:(id)factory selector:(SEL)selector;

    Swift

    class func withFactory(_ factory: Any!, selector: Selector!) -> Any!
  • Undocumented

    Declaration

    Objective-C

    + (id)withFactory:(id)factory selector:(SEL)selector parameters:(void (^)(TyphoonMethod *factoryMethod))params;

    Swift

    class func withFactory(_ factory: Any!, selector: Selector!, parameters params: ((TyphoonMethod?) -> Void)!) -> Any!
  • Undocumented

    Declaration

    Objective-C

    + (id)withFactory:(id)factory selector:(SEL)selector parameters:(void (^)(TyphoonMethod *factoryMethod))params configuration:(void(^)(TyphoonFactoryDefinition *definition))configuration;

    Swift

    class func withFactory(_ factory: Any!, selector: Selector!, parameters params: ((TyphoonMethod?) -> Void)!, configuration: ((TyphoonFactoryDefinition?) -> Void)!) -> Any!

Injection

  • Injects property with a component from the container that matches the type (class or protocol) of the property.

    Declaration

    Objective-C

    - (void)injectProperty:(SEL)withSelector;

    Swift

    func injectProperty(_ withSelector: Selector!)
  • Injects property for gives selector with injection, where injection can be

    • obtained from Injection* functions
    • another definition
    • assembly or collaboration assembly reference (TyphoonComponentFactory will be injected)
    • object instance

    Declaration

    Objective-C

    - (void)injectProperty:(SEL)selector with:(id)injection;

    Swift

    func injectProperty(_ selector: Selector!, with injection: Any!)
  • Injects method specified by selector with parameters.

    See

    TyphoonMethod documentation for information about parameters

    Declaration

    Objective-C

    - (void)injectMethod:(SEL)selector
              parameters:(void (^)(TyphoonMethod *))parametersBlock;

    Swift

    func injectMethod(_ selector: Selector!, parameters parametersBlock: ((TyphoonMethod?) -> Void)!)
  • Injects initializer specified by selector and parameters. Initializer allow you to create object with special selector and params. Without this injection, object will be created by ‘alloc-init’ calls

    Declaration

    Objective-C

    - (void)useInitializer:(SEL)selector
                parameters:(void (^)(TyphoonMethod *))parametersBlock;

    Swift

    func useInitializer(_ selector: Selector!, parameters parametersBlock: ((TyphoonMethod?) -> Void)!)
  • Convenience method to use a no-args initializer.

    Declaration

    Objective-C

    - (void)useInitializer:(SEL)selector;

    Swift

    func useInitializer(_ selector: Selector!)

Making injections from definition

  • Returns injection which can be used for example in injectProperty:with: method This method will injects result of selector invocation

    Declaration

    Objective-C

    - (id)property:(SEL)selector;

    Swift

    func property(_ selector: Selector!) -> Any!

    Parameters

    selector

    selector to invoke on resolved definition

  • Returns injection which can be used for example in injectProperty:with: method This method will injects valueForKeyPath: with given keyPath

    Declaration

    Objective-C

    - (id)keyPath:(NSString *)keyPath;

    Swift

    func keyPath(_ keyPath: String!) -> Any!

    Parameters

    keyPath

    path used as argument while calling valueForKeyPath: on resolved definition

Infrastructure

  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong) TyphoonRuntimeArguments *currentRuntimeArguments

    Swift

    var currentRuntimeArguments: TyphoonRuntimeArguments! { get set }
  • key

    The key of the component. A key is useful when multiple configuration of the same class or protocol are desired - for example MasterCardPaymentClient and VisaPaymentClient.

    If using the TyphoonBlockComponentFactory style of assembly, the key is automatically generated based on the selector name of the component, thus avoiding “magic strings” and providing better integration with IDE refactoring tools.

    Declaration

    Objective-C

    @property (nonatomic, strong) NSString *key;

    Swift

    var key: String! { get set }
  • Describes the initializer, ie the selector and arguments that will be used to instantiate this component.

    An initializer can be an instance method, a class method, or even a reference to another component’s method (see factory property).

    If no explicit initializer has been set, returns a default initializer representing the init method.

    See

    factory

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) TyphoonMethod *initializer;

    Swift

    var initializer: TyphoonMethod! { get }
  • Returns true if this is a default initializer generated by Typhoon. A manually specified initializer will return false, even if the selector is @selector(init)

    Declaration

    Objective-C

    @property (nonatomic, assign, unsafe_unretained, readwrite,
              getter=isInitializerGenerated) BOOL initializerGenerated;

    Swift

    var isInitializerGenerated: Bool { get set }
  • Returns a definition with the given class and key. In the block-style assembly, keys are auto-generated, however infrastructure components may specify their own key.

    Declaration

    Objective-C

    + (instancetype)withClass:(Class)clazz key:(NSString *)key;

    Swift

    class func withClass(_ clazz: AnyClass!, key: String!) -> Self!
  • Factory method for a TyphoonConfigPostProcessor.

    Declaration

    Objective-C

    + (instancetype)configDefinitionWithName:(NSString *)fileName;

    Swift

    class func configDefinition(withName fileName: String!) -> Self!

    Parameters

    fileName

    The config filename to load. File should be placed in main bundle

    Return Value

    a definition.

  • Factory method for a TyphoonConfigPostProcessor.

    Declaration

    Objective-C

    + (instancetype)configDefinitionWithPath:(NSString *)filePath;

    Swift

    class func configDefinition(withPath filePath: String!) -> Self!

    Parameters

    filePath

    The path to config file to load.

    Return Value

    a definition.

  • Undocumented

    Declaration

    Objective-C

    - (id)initWithClass:(Class)clazz key:(NSString *)key;

    Swift

    init!(with clazz: AnyClass!, key: String!)
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)matchesAutoInjectionWithType:(id)classOrProtocol includeSubclasses:(BOOL)includeSubclasses;

    Swift

    func matchesAutoInjection(withType classOrProtocol: Any!, includeSubclasses: Bool) -> Bool

Option

Deprecated

  • Deprecated

    Use performBeforeInjections method. (setBeforeInjections will be unavailable in Typhoon 3.0)

    Undocumented

    Declaration

    Objective-C

    - (void)setBeforeInjections:(SEL)sel DEPRECATED_MSG_ATTRIBUTE("Use performBeforeInjections method. (setBeforeInjections will be unavailable in Typhoon 3.0)");

    Swift

    func setBeforeInjections(_ sel: Selector!)
  • Deprecated

    Use performAterInjections method (setAfterInjections method will be unavailable in Typhoon 3.0)

    Undocumented

    Declaration

    Objective-C

    - (void)setAfterInjections:(SEL)sel DEPRECATED_MSG_ATTRIBUTE("Use performAterInjections method (setAfterInjections method will be unavailable in Typhoon 3.0)");

    Swift

    func setAfterInjections(_ sel: Selector!)

Unavailable

  • Unavailable

    Use TyphoonScopeLazySingleton instead

    Undocumented

    Declaration

    Objective-C

    @property(nonatomic, assign, getter = isLazy) BOOL lazy
  • Unavailable

    Use withFactory:selector: method instead

    Undocumented

    Declaration

    Objective-C

    + (id)withClass:(Class)clazz factory:(id)definition selector:(SEL)selector __attribute((unavailable("Use withFactory:selector: method instead")));
  • Unavailable

    Use configDefinitionWithName instead

    Undocumented

    Declaration

    Objective-C

    + (instancetype)configDefinitionWithResource:(id)resource __attribute__((unavailable("Use configDefinitionWithName instead")));
  • Unavailable

    Use configDefinitionWithName instead

    Undocumented

    Declaration

    Objective-C

    + (instancetype)configDefinitionWithResources:(NSArray *)array __attribute__((unavailable("Use configDefinitionWithName instead")));
  • Unavailable

    Use one of withFactory: method instead

    Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong) id factory