Giter VIP home page Giter VIP logo

Comments (3)

Suerous avatar Suerous commented on July 19, 2024

1.Aspects在你说的那三个问题中是不存在的。实验了一下这三种情况,KVO和Aspects可以工作良好。虽然不知道readme是因为忘记更新了,还是说有其他的问题存在(不是这其中的三个问题)

2.还有就是文章说到KVO是获取原类的。那解释第三个问题是因为isa被重新覆盖,那第一个同样的也会有isa被覆盖。KVO应该是获取isa对应的类,而不是class方法对应的原类。所以第三个问题应该是因为类继承关系混乱了,因为KVO的类只会生成一次。KVO__A----->KVO__A__Custom----->KVO__A--->A,猜测类继承冲突,系统直接是KVO__A--->A,对象a是KVO__A的实例,所以失效
1.先调用 custom-KVO 再调用 native-KVO,native-KVO 和 custom-KVO 都运行正常
2.先调用 native-KVO 再调用 custom-KVO,custom-KVO 运行正常,native-KVO 会 crash
3.先调用 native-KVO 再调用 custom-KVO 再调用 native-KVO,native-KVO 运行正常,custom-KVO 失效,无 crash

from sdmagichook.

gsdios avatar gsdios commented on July 19, 2024

1.Aspects在你说的那三个问题中是不存在的。实验了一下这三种情况,KVO和Aspects可以工作良好。虽然不知道readme是因为忘记更新了,还是说有其他的问题存在(不是这其中的三个问题)

2.还有就是文章说到KVO是获取原类的。那解释第三个问题是因为isa被重新覆盖,那第一个同样的也会有isa被覆盖。KVO应该是获取isa对应的类,而不是class方法对应的原类。所以第三个问题应该是因为类继承关系混乱了,因为KVO的类只会生成一次。KVO__A----->KVO__A__Custom----->KVO__A--->A,猜测类继承冲突,系统直接是KVO__A--->A,对象a是KVO__A的实例,所以失效
1.先调用 custom-KVO 再调用 native-KVO,native-KVO 和 custom-KVO 都运行正常
2.先调用 native-KVO 再调用 custom-KVO,custom-KVO 运行正常,native-KVO 会 crash
3.先调用 native-KVO 再调用 custom-KVO 再调用 native-KVO,native-KVO 运行正常,custom-KVO 失效,无 crash

//
//  AspectsViewController.m
//  AspectsDemo
//
//  Created by Peter Steinberger on 05/05/14.
//  Copyright (c) 2014 PSPDFKit GmbH. All rights reserved.
//

#import "AspectsViewController.h"
#import "Aspects.h"

@implementation AspectsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
    [self.view aspect_hookSelector:@selector(setFrame:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info, CGRect frame){
        NSLog(@"%@", [NSValue valueWithCGRect:frame]);
    } error:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    NSLog(@"%@", change);
}

@end
  1. 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
  2. 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?

@Suerous

from sdmagichook.

Suerous avatar Suerous commented on July 19, 2024

1.Aspects在你说的那三个问题中是不存在的。实验了一下这三种情况,KVO和Aspects可以工作良好。虽然不知道readme是因为忘记更新了,还是说有其他的问题存在(不是这其中的三个问题)
2.还有就是文章说到KVO是获取原类的。那解释第三个问题是因为isa被重新覆盖,那第一个同样的也会有isa被覆盖。KVO应该是获取isa对应的类,而不是class方法对应的原类。所以第三个问题应该是因为类继承关系混乱了,因为KVO的类只会生成一次。KVO__A----->KVO__A__Custom----->KVO__A--->A,猜测类继承冲突,系统直接是KVO__A--->A,对象a是KVO__A的实例,所以失效
1.先调用 custom-KVO 再调用 native-KVO,native-KVO 和 custom-KVO 都运行正常
2.先调用 native-KVO 再调用 custom-KVO,custom-KVO 运行正常,native-KVO 会 crash
3.先调用 native-KVO 再调用 custom-KVO 再调用 native-KVO,native-KVO 运行正常,custom-KVO 失效,无 crash

//
//  AspectsViewController.m
//  AspectsDemo
//
//  Created by Peter Steinberger on 05/05/14.
//  Copyright (c) 2014 PSPDFKit GmbH. All rights reserved.
//

#import "AspectsViewController.h"
#import "Aspects.h"

@implementation AspectsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
    [self.view aspect_hookSelector:@selector(setFrame:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info, CGRect frame){
        NSLog(@"%@", [NSValue valueWithCGRect:frame]);
    } error:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    NSLog(@"%@", change);
}

@end
  1. 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
  2. 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?

@Suerous

1.Aspects在你说的那三个问题中是不存在的。实验了一下这三种情况,KVO和Aspects可以工作良好。虽然不知道readme是因为忘记更新了,还是说有其他的问题存在(不是这其中的三个问题)
2.还有就是文章说到KVO是获取原类的。那解释第三个问题是因为isa被重新覆盖,那第一个同样的也会有isa被覆盖。KVO应该是获取isa对应的类,而不是class方法对应的原类。所以第三个问题应该是因为类继承关系混乱了,因为KVO的类只会生成一次。KVO__A----->KVO__A__Custom----->KVO__A--->A,猜测类继承冲突,系统直接是KVO__A--->A,对象a是KVO__A的实例,所以失效
1.先调用 custom-KVO 再调用 native-KVO,native-KVO 和 custom-KVO 都运行正常
2.先调用 native-KVO 再调用 custom-KVO,custom-KVO 运行正常,native-KVO 会 crash
3.先调用 native-KVO 再调用 custom-KVO 再调用 native-KVO,native-KVO 运行正常,custom-KVO 失效,无 crash

//
//  AspectsViewController.m
//  AspectsDemo
//
//  Created by Peter Steinberger on 05/05/14.
//  Copyright (c) 2014 PSPDFKit GmbH. All rights reserved.
//

#import "AspectsViewController.h"
#import "Aspects.h"

@implementation AspectsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
    [self.view aspect_hookSelector:@selector(setFrame:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info, CGRect frame){
        NSLog(@"%@", [NSValue valueWithCGRect:frame]);
    } error:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    NSLog(@"%@", change);
}

@end
  1. 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
  2. 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?

@Suerous

1.按照你跑的代码确实是崩溃了。所以我也在问是不是其他的情况,我看你的demo写的num属性。所以我是用的name属性测试的这三种情况,是运行成功的。
[aspectsController addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
aspectsController.name = @"1";
[AspectsViewController aspect_hookSelector:@selector(setName:) withOptions:0 usingBlock:^(id info, NSString *name) {
NSLog(@"2aspect hook----%@", name);
} error:nil];

2.我并没有说meta class的问题,特定对象的hook和meta class也扯不上啊,我说的就是你文章说的原类(原来的类)。我还特地写了类的继承关系。我说的是KVO是获取对象的isa生成子类的,而不是原来的类。所以我才写了类的继承关系。现在我大概明白了,nativeKVO是先看class方法类对象有没有被创建过,没有就通过对象的isa生成子类,有的话,直接用。这样情况1就能说通了,不会和情况3解释有冲突了。我一直以为你说的是KVO一直按class方法(原来的类)去获取/创建子类,这样情况1就说不通了。这就是我没看懂过来问这个原类的问题

from sdmagichook.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.