Comments (3)
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.
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
- 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
- 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?
from sdmagichook.
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
- 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
- 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?
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
- 试下在Aspects的demo里面这样分别用系统的kov和aspects监听下setFrame方法会不会crash,认真跑下代码试下然后给下最新的结论
- 文章中出现过的词是原类(即原来的类)而非 元类(meta class),先把这两个概念搞清楚。具体什么问题导致不兼容可以先把demo运行起来跑一下看下实际情况再说。文章上已经讲的的很详细,对照着run一下?
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)
- 您这个和Aspects的instance hook有什么不同吗😂 HOT 7
- 使用这个库,影响上架吗 HOT 1
- 用于打点, 如何Hook所有继承某个类的实例函数,而不是仅仅某一个实例的函数 HOT 1
- iOS 14.5崩溃 HOT 3
- release环境 最新iOS15多的系统 卡主了
- SDOrderedDict 这个类的命名有点不合适
- 这个库功能跟aspects基本一样,只有api上有细微差点……建议写相关功能先调研一下相关的库,避免重复造轮子 HOT 1
- demo0 KVO crash HOT 3
- 代码应该在哪里编写 HOT 2
- 这个是不是只能对已知的实例(或者说自己生成的实例)进行hook HOT 3
- swift 调用 请检查你是否在hook了 `pointInside:withEvent:` 方法之后忘记调用原始方法。 HOT 1
- hook方法后,不调用以前hook的方法崩溃 HOT 2
- Crash Issue HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdmagichook.