나는이 문제를 해결하기 위해 하루 종일 고생했습니다. 아이템의 NSMutableArray가 있습니다. 때로는 응용 프로그램 수명주기 동안 응용 프로그램이 거기에 객체를 밀고 팝합니다. 나는 보통 $ scope. $ watch와 함께 AngularJS 측에서 이것을 할 수 있습니다. 나는이 행동의 일부를하기 위해 그 동안 ReactiveCocoa를 사용 해왔다.
본질적으로 나는이 사건을 일으키는 블록을 원한다.
- (void) fetchAllItems; - (void) 푸시 : (id) 항목; - (void) pop : (NSUInteger) index;
ReactiveCocoa로 시도했지만 결코 실행되지 않습니다! 당신은 속성 setter를 구현하고 있기 때문에
[RACObserve(singletonStore, items) subscribeNext:^(NSArray *wholeArray) {
NSUInteger count = [wholeArray count];
[self.offerCircleButton setTitle:[NSString stringWithFormat:@"%d", count]]
}];
항목 속성이
@property (nonatomic, copy) NSArray *items;
게터와 세터로 singletonStore 객체 선언은 전용 변수
@interface SHSingletonStore()
{
NSMutableArray *_items;
}
@end
-(NSArray *)items {
return [_items copy];
}
-(void)setItems:(NSArray *)items{
if([_items isEqualToArray:items] == NO){
_items = [items mutableCopy];
}
}
모든 종류의 배열 문제에 대해 선택기 수신기 블록이 내장되어 있다고 생각했지만 직접해야한다고 생각합니다! –
당신의 질문은 ReactiveCocoa로 어레이 변경 사항을 관찰하는 것과 관련된 다른 질문과 비슷합니다. 도움이 필요할 경우를 대비해서 제가 지적했습니다 : http://stackoverflow.com/questions/25162893/racobserve-for-value -update-in-nsmutablearray – erikprice