reactive cocoa - Is there something similar to $scope.$watch for NSMutableArray -


i've been struggling day working correct. have nsmutablearray of items. during application lifecycle, app push , pop objects in there. can on angularjs side $scope.$watch. i've been using reactivecocoa in meantime of behavior

essentially i'd block fire on these events.

-(void)fetchallitems; -(void)push:(id)item; -(void)pop:(nsuinteger)index;

i tried reactivecocoa never fires!

[racobserve(singletonstore, items) subscribenext:^(nsarray *wholearray) {         nsuinteger count = [wholearray count];         [self.offercirclebutton settitle:[nsstring stringwithformat:@"%d", count]]  }]; 

the items property declared in singletonstore object as

@property (nonatomic, copy) nsarray *items; 

the getter , setter nsmutablearray private variable

@interface shsingletonstore() {     nsmutablearray *_items; } @end  -(nsarray *)items {     return [_items copy]; }  -(void)setitems:(nsarray *)items{     if([_items isequaltoarray:items] == no){         _items = [items mutablecopy];     } } 

essentially i'd block fire on these events.

-(void)fetchallitems; -(void)push:(id)item; -(void)pop:(nsuinteger)index;

if saying want signal sends value whenever of methods called, can -rac_signalforselector:, so:

sel fetchallsel = @selector(fetchallitems); racsignal *fetchallsignal = [singletonstore rac_signalforselector:fetchallsel];  sel pushsel = @selector(push:); racsignal *pushsignal = [singletonstore rac_signalforselector:pushsel];  sel popsel = @selector(pop:); racsignal *popsignal = [singletonstore rac_signalforselector:popsel];  @weakify(self); [[racsignal merge:@[ fetchallsignal, pushsignal, popsignal ]] subscribenext:^(id _) {      @strongify(self);     [self.offercirclebutton settitle:[nsstring stringwithformat:@"%d", singletonstore.items.count]]  }]; 

this solution kind of gross, because each of individual merged signals sends different type of value (so end signal can send 3 different types of value, not cool), if ignoring value can perform side effect based on global state, doesn't matter.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -