Multicast Delegation in Typhoon -
i'm using multicast delegation in project , i'd integrate typhoon using standard one-to-one objective-c delegates.
as multicast delegation, i'm using nsproxy approach, explained here: http://arielelkin.github.io/articles/objective-c-multicast-delegate/.
my code far:
-(aviewcontroller*)aviewcontroller{ homecoming [typhoondefinition withclass:[aviewcontroller class] configuration:^(typhoondefinition *definition) { }]; } -(bviewcontroller*)bviewcontroller{ homecoming [typhoondefinition withclass:[bviewcontroller class] configuration:^(typhoondefinition *definition) { }]; } -(appcontroller*)appcontroller{ homecoming [typhoondefinition withclass:[appcontroller class] configuration:^(typhoondefinition *definition) { [definition setscope:typhoonscopesingleton]; [definition injectproperty:@selector(delegate) with:[self appcontrollermulticastdelegate]]; }]; } -(multicastdelegate*)appcontrollermulticastdelegate{ homecoming [typhoondefinition withclass:[multicastdelegate class] configuration:^(typhoondefinition *definition) { [definition setscope:typhoonscopesingleton]; }]; }
is possible inject aviewcontroller , bviewcontroller appcontrollermulticastdelegation? how should solve issue? think should utilize method injection (for adddelegate: method in multicastdelegate), have no thought how it...
edit asking. possible inject instance current definition (non-singleton - typhoonscopeobjectgraph) other definition, (method injection):
-(aviewcontroller*)aviewcontroller{ homecoming [typhoondefinition withclass:[aviewcontroller class] configuration:^(typhoondefinition *definition) { [(typhoondefinition*)[self appcontollermulticastdelegate] injectmethod:@selector(adddelegate:) parameters:^(typhoonmethod *method) { [method injectparameterwith:/*instance of aviewcontroller created*/]; }]; }
on runtime: aviewcontroller* aviewcontroller = [(myassembly*)factory aviewcontroller];// creates new unique instance of aviewcontroller , adds appcontollermulticastdelegate subscribers;
since view controllers have typhoonscopeobjectgraph necessary to:
register multicast delegate on creation detach before destroying.unfortunately not possible wire using typhoon, you'd have in view controller.
the registration part done:
add a new property of type multicastdelegate uiviewcontrolleradd category methods:
- (void)registerwithdelegate { self.delegate addsubscriber:self]; }
then when registering view controller:
- (bviewcontroller *)bviewcontroller { homecoming [typhoondefinition withclass:[bviewcontroller class] configuration:^(typhoondefinition *definition) { [definition injectproperty:@selector(delegate) with:[self appcontrollermulticastdelegate]]; definition.beforeinjections = @selector(registerwithdelegate); }]; }
but unfortunately typhoon not have hooks dealloc of component.
instead simply:
- (void)dealloc { [_delegate removesubscruber:self]; }
possible useful feature:
here's typhoon doesn't do, potentially interesting feature: define before/after injection callbacks arguments, such as:
[definition invokebeforeinjection:@selector(registerwithdelegate:) parameters:^(typhoonmethod *method) { [method injectparameterwith:[self multicastdelegate]; }
by way, there reason prefer hand-rolled multicast delegates on apple's nsnotificationcenter?
typhoon
No comments:
Post a Comment