当前位置:网站首页>KVO summary
KVO summary
2022-06-22 07:41:00 【Siege lion corn】
@interface KvoOperation : NSOperation
@property (nonatomic, getter=isFinished) BOOL finished;
@property (nonatomic, strong) NSString *k;
@property (nonatomic, strong) NSMutableArray *mutArr;
-(void)insertObject:(id)object inMutArrAtIndex:(NSInteger)index;
@end
@implementation KvoOperation
@synthesize finished = _finished;
@synthesize k = _k;
@synthesize mutArr = _mutArr;
+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
return NO;
}
- (void)setK:(NSString *)k {
[self willChangeValueForKey:@"k"];
_k = k;
[self didChangeValueForKey:@"k"];
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"];
_finished = finished;
[self didChangeValueForKey:@"isFinished"];
}
-(void)insertObject:(id)object inMutArrAtIndex:(NSInteger)index {
[self willChange:(NSKeyValueChangeInsertion) valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"mutArr"];
[_mutArr insertObject:object atIndex:index];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"mutArr"];
}
@end+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key return NO It can shield the native set Method of departure kvo monitor , But for manual implementation kvo Invalid .
Manually triggered by non collection types kvo :willChangeValueForKey:、didChangeValueForKey: , Not subject to automaticallyNotifiesObserversForKey: shielding
Collection types (eg NSMutableArray) increase 、 Delete 、 Replace item Can't trigger kvo, If you use mutableArrayValueForKey: obtain mArr, increase 、 Delete 、 Replace item Can trigger kvo, And by automaticallyNotifiesObserversForKey: Method shielding effect
NSMutableArray *mArr = [_kvoOption mutableArrayValueForKey:@"mutArr"];
[mArr addObject:@"a"];Set type increase 、 Delete 、 Replace item Manual trigger kvo : For example, call the following method when inserting , Can trigger kvo, Not subject to automaticallyNotifiesObserversForKey: shielding
-(void)insertObject:(id)object inMutArrAtIndex:(NSInteger)index {
[self willChange:(NSKeyValueChangeInsertion) valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"mutArr"];
[_mutArr insertObject:object atIndex:index];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:[NSIndexSet indexSetWithIndex:index] forKey:@"mutArr"];
}- Mark:NSOperation finished Property is read-only , Rewrite here , By manually triggering finished kvo, Reach trigger completionBlock Purpose
边栏推荐
- [usecols parameter of pd.read\u excel ((), list error reason]
- Téléchargement de toutes les versions de chromedriver
- Docker command, docker installation sqlserver2019, docker installation MySQL (continuous update)
- Crmeb mall order shipping function
- 充电宝的玄机
- ASP. Net core development experience
- enable_ irq_ Wake interrupt wakes up the kernel in low power mode
- How to view cookies in Chrome browser
- Asyncstorage quick start
- Ffmpeg pit
猜你喜欢

Kuangshi brain++ Tianyuan platform megstudio

JS gets all child nodes under a div natively

What if the finder fails to respond continuously? Finder unresponsive solution tutorial

A training summary of Intranet penetration test

Propeller framework v2.3 releases high reusable operator library Phi: Restructure development paradigm, reduce cost and increase efficiency

Xlua environment configuration

Remote Desktop Manager

Solution to the problem of "brand abuse such as brand inconsistency and stacking in the published product information" prompted by copying and uploading

Applet /vant UI to upload files

ES6 set data type de duplication of array, intersection, union and difference
随机推荐
AutoCAD 2020.3中文版 (旧版本)
JS 数组扁平化 (递归写法)
Chromedriver所有版本下載
Solve syntaxerror: cannot use import statement outside a module
由浅入深拿下OpenFeign
5、 Image component
Itemtools permutation
selenium防爬和模拟手机浏览器
Kuangshi brain++ Tianyuan platform megstudio
AudioQueue
[v4.3] the applet fails to receive the subscription message, and the coupon time on the product details page is displayed incorrectly
A training summary of Intranet penetration test
Selenium anti crawl and analog mobile browser
【图论常见模板题】4种最短路解法和2种最小生成树解法
lr 2022超详细安装教程「最新」
New year's Day mall material Icon
An example shows the difference between let and VaR
6、 Scrollview component
Xlua environment configuration
Flutter black triangle