Observe object change in NSArray using ReactiveCocoa

Viewed 1151

I'm creating simple contact application trying to learn ReactiveCocoa and MVVM. I store array of cell's ViewModels in my tableView's ViewModel. When user enters into tableView's editing mode, some properties of some cell's ViewModel can be changed as user changes cell text. I want to observe these changes in order to enable/disable Done button and accordingly enable/disable signal for saving the data to the model. How can I observe these changes in the tableViews view model?

Here is a snippet of code I tried to use:

-(RACSignal *)executeCheckChange {
    return [RACObserve(self, cellViewModels)
            map:^id(NSArray *viewModels) {
                for (id viewModel in viewModels) {
                    if([viewModel isKindOfClass:[STContactDetailsPhoneCellViewModel class]])
                    {
                        STContactDetailsPhoneCellViewModel *phoneViewModel = (STContactDetailsPhoneCellViewModel *)viewModel;
                        if([phoneViewModel isChanged])
                            return @(YES);
                    }
                }
                return @(NO);
            }];
}

But this RACObserve is only invoked if the array itself is changed, but not the element of array.

2 Answers
Related