zoukankan      html  css  js  c++  java
  • kvo的observationInfo

    观察者信息的注册:

    <NSKeyValueObservationInfo 0x600000708d60> (

    <NSKeyValueObservance 0x6000009143f0: Observer: 0x7f9a0b508ef0, Key path: tpStr, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x600000914480>

    <NSKeyValueObservance 0x600000914420: Observer: 0x7f9a0b508ef0, Key path: eggo, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x6000009146f0>

    )

    /* Take or return a pointer that identifies information about all of the observers that are registered with the receiver, the options that were used at registration-time, etc. The default implementation of these methods store observation info in a global dictionary keyed by the receivers' pointers. For improved performance, you can override these methods to store the opaque data pointer in an instance variable. Overrides of these methods must not attempt to send Objective-C messages to the passed-in observation info, including -retain and -release.

    */

    @property (nullable) void *observationInfo NS_RETURNS_INNER_POINTER;

    函数调用栈:

    Foundation`-[NSObject(NSKeyValueObservingCustomization) observationInfo]

    Foundation`_NSKeyValueRetainedObservationInfoForObject + 53

    Foundation`-[NSObject(NSKeyValueObserverRegistration) _addObserver:forProperty:options:context:] + 337

    Foundation`-[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 103

    @interface ViewController ()

    @property(nonatomic, strong) NSString *pt;

    @end

    编译系统自动生成设置访问控制;编译系统自动生成kvc控制符;

    kvo在这个基础上执行;

    所有的kvc操作控制在编译前都已经完成;

    属性的kvc操作在编译后运行前完成;

    setvalue:for相关的操作属于运行时系统;在kvo的机制能能截获。

    self.pt = @"ddddd";

    [ViewController setPt:]

    https://github.com/farcaller/cocotron/blob/af740de86c9bee84c59ffc74d27e5df9e22e1391/Foundation/NSKeyValueCoding/NSKeyValueObserving.m

       // set info options
       info->observer=observer;
       info->options=options;
       info->context=context;
       info->object=self;
       [info setKeyPath:keyPath];
    -(void)setObservationInfo:(void*)info
    {
    	if(!observationInfos)
    		observationInfos=[NSMutableDictionary new];
    	[observationInfos setObject:[NSValue valueWithPointer:info] forKey:[NSValue valueWithPointer:self]];
    }
    
    +(void*)observationInfo
    {
    	return [[observationInfos objectForKey:[NSValue valueWithPointer:self]] pointerValue];
    }
    
    +(void)setObservationInfo:(void*)info
    {
    	if(!observationInfos)
    		observationInfos=[NSMutableDictionary new];
    	[observationInfos setObject:[NSValue valueWithPointer:info] forKey:[NSValue valueWithPointer:self]];
  • 相关阅读:
    NIO与普通IO文件读写性能对比
    JAVA学习.java.sql.date 与java.util.date以及gettime()方法的分析
    软件工程之软件设计
    ubuntu下管理android手机
    AFNetworking2.0 NSHipster翻译
    【Jsoup爬取网页内容】
    IOS 表视图UITableView 束NSBundle
    如何将位图格式图片文件(.bmp)生成geotiff格式图片?
    opencv3 使用glob遍历并修改文件名
    Ubuntu clion下载及激活
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10431411.html
Copyright © 2011-2022 走看看