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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -