Watch 1 Star 0 Fork 0

两好三坏 / iOSTestToolObjective-C

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
ios 研究性质的代码, 包括新技术,底层原理, 面试剖析等等 spread retract

Clone or download
QKKVOTestCtrl.m 1.44 KB
Copy Edit Web IDE Raw Blame History
两好三坏 authored 2018-12-29 14:47 . wkwebview
//
// QKKVOTestCtrl.m
// testTool
//
// Created by Su on 2018/12/17.
// Copyright © 2018 com.qiankun. All rights reserved.
//
#import "QKKVOTestCtrl.h"
#import "QKTestObject.h"
#import "QKTestObserver.h"
@interface QKKVOTestCtrl ()
@end
@implementation QKKVOTestCtrl
-(void)injected{
[self viewDidLoad];
}
- (void)viewDidLoad {
[super viewDidLoad];
QKTestObject *obj = [[QKTestObject alloc] init];
QKTestObserver *observer = QKTestObserver.alloc.init;
// 通过 KVO 监听 obj 的变化
[obj addObserver:observer forKeyPath:@"value" options:NSKeyValueObservingOptionNew context:NULL];
// 通过 setter 修改 value, 监听生效
// obj.value = 2;
// 通过 kvo 修改 value , 监听生效
// [obj setValue:@4 forKey:@"value"];
// 通过成员变量赋值. 未执行监听方法中的输出
/*
成员变量需要手动 添加 KVO , 监听才会生效
[self willChangeValueForKey:@"value"];
_value += 1;
[self didChangeValueForKey:@"value"];
*/
[obj changeValue];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end

Comment ( 0 )

You need to Sign in for post a comment

Help Search