Eric Chuang
Eric Chuang

Reputation: 1027

How can I trigger RACSignal combine latest with update to NSArray?

I am new to Reactive Cocoa and having trouble understanding it. But here is how I am using RACObserve & RACSignal. In my viewDidLoad:

 [[RACSignal combineLatest:@[RACObserve(self, cellArray)]] subscribeNext:^(id x) { 
// I've set a breakpoint here.
 }];

I want to trigger the above code/block when I update cellArray (NSMutableArray). I'm getting data via an API and adding the data to my cellArray like this:

[self.cellArray insertObject:item atIndex:x];

Or

[self.cellArray addObject:item];

Am I implementing this properly?

Upvotes: 1

Views: 182

Answers (1)

Rui Peres
Rui Peres

Reputation: 25927

You can't observe insertions/deletions in an array like that. This has been discussed extensively before. Have a look at this solution in RAC's repo. Basically in your case would like:

NSMutableArray *contents = [self mutableArrayValueForKey:"cellArray"];
[contents addObject: item];

Upvotes: 1

Related Questions