GBIvarsProvider Class Reference
Inherits from | NSObject |
Declared in | GBIvarsProvider.h GBIvarsProvider.m |
Overview
A helper class that unifies ivars handling.
Dividing implementation of ivars provider to a separate class allows us to abstract the logic and reuse it within any object that needs to handle ivars using composition. This breaks down the code into simpler and more managable chunks. It also simplifies ivars parsing and handling. To use the class, simply "plug" it to the class that needs to handle ivars and provide access through public interface.
The downside is that querrying code becomes a bit more verbose as another method or property needs to be sent before getting access to actual ivars data.
Tasks
Initialization & disposal
-
– initWithParentObject:
Initializes ivars provider with the given parent object.
Ivars handling
-
– registerIvar:
Registers the given ivar to the providers data. -
– mergeDataFromIvarsProvider:
Merges data from the given ivars provider. -
ivars
The array of all registered ivars asGBIvarData
instances in the order of registration. property
Instance Methods
initWithParentObject:
Initializes ivars provider with the given parent object.
- (id)initWithParentObject:(id)parent
Parameters
- parent
- The parent object to be used for all registered ivars.
Return Value
Returns initialized object.
Discussion
The given parent object is set to each GBIvarData
registered through registerIvar:
. This is the designated initializer.
Exceptions
- NSException
- Thrown if the given parent is
nil
.
Declared In
GBIvarsProvider.h
mergeDataFromIvarsProvider:
Merges data from the given ivars provider.
- (void)mergeDataFromIvarsProvider:(GBIvarsProvider *)source
Parameters
- source
GBIvarsProvider
to merge from.
Discussion
This copies all unknown ivars from the given source to receiver and invokes merging of data for receivers ivars also found in source. It leaves source data intact.
Declared In
GBIvarsProvider.h
registerIvar:
Registers the given ivar to the providers data.
- (void)registerIvar:(GBIvarData *)ivar
Parameters
- ivar
- The ivar to register.
Discussion
If provider doesn't yet have the given ivar instance registered, the object is added to ivars
list. If the same object is already registered, nothing happens.
Note: If another instance of the ivar with the same name is registered, an exception is thrown.
Exceptions
- NSException
- Thrown if the given ivar is already registered.
Declared In
GBIvarsProvider.h