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]];
  • 相关阅读:
    React爬坑秘籍(一)——提升渲染性能
    (转)Chrome开发者工具不完全指南(一、基础功能篇)
    React-Todos
    webpack前端模块加载工具
    Python面试笔记二
    Python面试笔记一
    Python面试笔记四
    Python面试笔记三
    Mysql性能优化一
    公共的JS组件-告别CURD
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10431411.html
Copyright © 2011-2022 走看看