• 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]];
  • 相关阅读:
    C#对象深度克隆(转)
    .Net Core 图片文件上传下载(转)
    事件总线(Event Bus)知多少(转)
    深入理解C#:编程技巧总结(一)(转)
    asp.net core源码飘香:Configuration组件(转)
    asp.net core源码飘香:Logging组件(转)
    基于C#.NET的高端智能化网络爬虫(下)(转)
    基于C#.NET的高端智能化网络爬虫(转)
    30分钟掌握 C#7(转)
    30分钟掌握 C#6(转)
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10431411.html
Copyright © 2020-2023  润新知