Reputation: 8991
I'm trying to use ReactiveCocoa to enable a button depending on if the number of objects in an NSMutableSet instance is greater than zero.
I am using the following code, but am experiencing a crash at runtime. Any ideas?
RAC(self.navigationItem.leftBarButtonItem, enabled) = [RACSignal combineLatest:@[self.selectedRows] reduce:^(NSMutableSet *set){
return @([set count] > 0);
}];
'NSInvalidArgumentException', reason: '-[__NSSetM map:]: unrecognized selector sent to instance 0x9671d10'
Upvotes: 1
Views: 1582
Reputation: 1673
Thats sad to know that NSarry, NSMutableArray do not support KVO. While doing something similar
But thankfully, UIViewController is KVO compliant.
//create a readonly property selectionCount
@property (nonatomic, readonly)NSInteger selectionCount;
...
//Implement the getter method
-(NSInteger)selectionCount{
return self.arrSelection.count;
}
...
RAC(self.btnConfirm, enabled) = [RACSignal combineLatest:@[RACAbleWithStart(self.selectionCount)] reduce:^(NSNumber *count){
return @([count integerValue] > 0);
}];
Upvotes: 0
Reputation: 12421
You need to turn your selectedRows
property into a signal:
RAC(self.navigationItem.leftBarButtonItem, enabled) = [RACSignal combineLatest:@[RACAbleWithStart(self.selectedRows)] reduce:^(NSMutableSet *set){
return @([set count] > 0);
}];
Upvotes: 1