KRHub

Objective-C

@interface KRHub : NSObject

Swift

class KRHub : NSObject

A KRHub object can easily become a container of references to other objects or classes, organized in groups. To be able to register themselves with a KRHub, objects must implement the KRAdapter protocol. Within a single group there can not be more objects that declare the same type.

  • Returns the list of available registered objects for a specified group.

    Declaration

    Objective-C

    - (NSMutableDictionary *_Nullable)adaptersForGroup:(NSString *_Nonnull)group;

    Swift

    func adapters(forGroup group: String) -> NSMutableDictionary?

    Parameters

    group

    The required group.

    Return Value

    A dictionary containing all objects registered for the required group. The dictionary keys are the types, as specified by the objects.

  • Registers a new adapter to the default group.

    Declaration

    Objective-C

    - (void)registerAdapter:(NSObject<KRAdapter> *_Nonnull)adapter;

    Swift

    func register(_ adapter: KRAdapter)

    Parameters

    adapter

    The adapter to be registered. The object needs to implement KRAdapter.

  • Returns an object of the specified type, if such an object is currently registered in the default group.

    Declaration

    Objective-C

    - (NSObject<KRAdapter> *_Nullable)adapterForType:(NSString *_Nonnull)type;

    Swift

    func adapter(forType type: String) -> KRAdapter?

    Parameters

    type

    The required object type.

    Return Value

    An object if any is registered, nil otherwise.

  • Registeres a new adapter to a specific group

    Declaration

    Objective-C

    - (void)registerAdapter:(NSObject<KRAdapter> *_Nonnull)adapter
                    inGroup:(NSString *_Nullable)group;

    Swift

    func register(_ adapter: KRAdapter, inGroup group: String?)

    Parameters

    adapter

    The adapter to be registered. The object needs to implement KRAdapter.

    group

    The group to register the adapter into.

  • Returns an object of the specified type, if such an object is currently registered in the specified group.

    Declaration

    Objective-C

    - (NSObject<KRAdapter> *_Nullable)adapterForType:(NSString *_Nonnull)type
                                             inGroup:(NSString *_Nullable)group;

    Swift

    func adapter(forType type: String, inGroup group: String?) -> KRAdapter?

    Parameters

    type

    The required object type.

    group

    The required group.

    Return Value

    An object if any is registered, nil otherwise.

  • Registers a class to a specific group and a specific type. Upon requesting a new object from this group and type, a new object of the registered class will be instantiated and returned.

    Declaration

    Objective-C

    - (void)registerClass:(Class _Nonnull)cclass inGroup:(NSString *_Nullable)group;

    Swift

    func register(_ cclass: AnyClass, inGroup group: String?)

    Parameters

    cclass

    The class to register.

    group

    The group to register the call into.

  • Registers a class to the default group, under a specific type. Upon requesting a new object from this type from the default group, a new object of the registered class will be instantiated and returned.

    Declaration

    Objective-C

    - (void)registerClass:(Class _Nonnull)cclass;

    Swift

    func register(_ cclass: AnyClass)

    Parameters

    cclass

    The class to register