ios - ReactiveCocoa repeat command does not use modified values -


i trying write code iterates forever, , here how have written it:

- (void) testrepeat {  __block dataclass * dc = [[dataclass alloc] init];     [[[[self repeatfunc:dc ]          donext:^(id x) {      dc = nil;   }]   repeat]    subscribenext:^(id x) {     nslog(@"next");  } completed:^{     nslog(@"completed");  }]; }  - (racsignal *) repeatfunc: (dataclass *) dc {  return [racsignal createsignal:^racdisposable *(id<racsubscriber> subscriber) {     nslog(@"dc : %@", dc);     [subscriber sendnext:nil];     [subscriber sendcompleted];     return nil;  }];  } 

the first time code iterates, value object "dc" correct. after first call repeatfunc, setting "dc" nil, however, when iterates back, change in "dc" not reflected , still previous value.

what correct way achieve above purpose?

the method -repeatfunc: captures immutable reference own pointer dc, , each repeat sends reference, not local reference have nil'd out.

it done so:

__block dataclass *dc = [[dataclass alloc] init]; racsignal *signal = [[[racsignal     defer:^{         return [racsignal return:dc];     }]     donext:^(id x) {         dc = nil;     }]     repeat]; 

but more functional way express be:

[[[racsignal return:nil] repeat] startwith:dc]; 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -