Skip to content

由于Object-C中NSMutableArray等可变集合不能kvo,所以使用ReactiveObjC实现观察NSMutableArray 等可变集合内容变化,得到KVO效果,用来触发数据源.

License

Notifications You must be signed in to change notification settings

axinger/AXCollectionObserve

Repository files navigation

AXCollectionObserve

由于Object-C中NSMutableArray等可变集合不能kvo,所以使用ReactiveObjC实现观察NSMutableArray 等可变集合内容变化,得到KVO效果,用来触发数据源.

Example

NSMutableArray

@weakify(self)
[RACObserve(self, array) ax_subscribeNext:^(id  _Nonnull x) {
    @strongify(self)
    doSoming;
}];
NSMutableArray *array = NSMutableArray.array;
[array ax_valueChangeObserve:^(NSMutableArray * _Nonnull array) {
  NSLog(@"array = %@",array);
}];
/// 添加元素
NSString *str = [NSString stringWithFormat:@"array-%ld",array.count];
[array addObject:str];

NSString *str = [NSString stringWithFormat:@"array-%ld",array.count];
[array insertObject:str atIndex:0];

if (array.count>0) {
  [array removeLastObject];
}

NSMutableDictionary

NSMutableDictionary *dict = NSMutableDictionary.dictionary;
[dict ax_valueChangeObserve:^(NSMutableDictionary * _Nonnull dict) {
	NSLog(@"dict = %@",dict);
}];

NSString *key = [NSString stringWithFormat:@"key-%ld",dict.count];
dict[key] = key;

Requirements

Installation

AXCollectionObserve is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'AXCollectionObserve'

或者

pod 'AXCollectionObserve',:git => 'https://gitee.com/axinger/AXCollectionObserve.git'

Author

axinger, [email protected]

License

AXCollectionObserve is available under the MIT license. See the LICENSE file for more info.

About

由于Object-C中NSMutableArray等可变集合不能kvo,所以使用ReactiveObjC实现观察NSMutableArray 等可变集合内容变化,得到KVO效果,用来触发数据源.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published