Monday, 15 April 2013

objective c - How to store an init call in an NSInvocation? -



objective c - How to store an init call in an NSInvocation? -

i'm trying set app works uipageviewcontroller. technically instantiate view @ 1 time , set them in array, expensive, , seems improve initialize views needed. read nsinvocation message rendered static-- thinking have array contains: [subclassa alloc]init], [subclassb alloc]init], etc... messages wrapped in nsinvocation. homecoming result of message in pageviewcontroller:viewcontrollerafter/beforeviewcontroller:.

i'm still pretty new @ this, possible fundamentally misunderstanding nsinvocation, either way, reply still helpful.

sounds want kind of lazy instantiation.

you can utilize helper class

@interface lazyobject : nsobject @property (copy) id (^block)(void)); @property (readonly) id object; + (instancetype)create:(id (^)(void))block; @end @implementation lazyobject { id _object; } + (instancetype)create:(id (^)(void))block { lazyobject *obj = [[self alloc] init]; obj.block = block; homecoming obj; } - (id)object { if (!_object) _object = self.block(); homecoming _object; } @end nsarray *array = @[[lazyobject create:^id{ homecoming [[someclassa alloc] init];}], [lazyobject create:^id{ homecoming [[someclassb alloc] init];}]]; someclassa *a = [array[0] object]; someclassb *b = [array[1] object];

as others said, nsinvocation not solution original problem. designed invoke method dynamically. don't need of cases.

objective-c nsarray uipageviewcontroller nsinvocation

No comments:

Post a Comment