• objc学习摘录


    KVO使用的方法

    /** 
     * Used by Foundation's Key-Value Observing.
     * 
     * @warning Do not call this function yourself.
     */
    OBJC_EXPORT Class objc_duplicateClass(Class original, const char *name, size_t extraBytes)
         __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
    UIViewController
    
    [self addObserver:self forKeyPath:@"intValue" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
    self.intValue = 1230;
    
    /// 一般的属性也会触发该方法调用 storyboard mswitch psegment sswitch view
    - (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
        [super setValue:value forKeyPath:keyPath];
        NSLog(@"通过KVC设置值key:%@", keyPath);
    }
    /// 一般的属性也会触发该方法调用 storyboard mswitch psegment sswitch view
    - (void)setValue:(id)value forKey:(NSString *)key {
        [super setValue:value forKey:key];
        NSLog(@"设置Key-Value对key:%@", key);
    }
    /// 这个函数在调用addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:之后对应属性变化才会调用
    - (void)didChangeValueForKey:(NSString *)key {
        NSLog(@"已经改变key:%@",key);
        [super didChangeValueForKey:key];
    }
    
    /// 这个函数在调用addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:之后对应属性变化才会调用
    - (void)willChangeValueForKey:(NSString *)key {
        NSLog(@"即将改变key:%@",key);
        [super willChangeValueForKey:key];
    }
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
        NSLog(@"接收到消息改变key:%@
    %@",keyPath,change);
    }
  • 相关阅读:
    mybatis动态SQl中int类型字段为0 SQl语句不拼接
    Ansible学习(pyenv与virtualenv)
    word
    github学习
    OpenStack搭建遇到的问题2(组件配置错误了,别重装全部,就把模块卸载就行了)
    OpenStack搭建遇到的问题
    Ubuntu 17.04 安装
    docker学习(一)
    MySQL安装
    来自Google的响应式——Agera
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/13840730.html
Copyright © 2020-2023  润新知