Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类方法和实例方法调用有个写反了 #131

Open
imqiuhang opened this issue May 11, 2020 · 0 comments
Open

类方法和实例方法调用有个写反了 #131

imqiuhang opened this issue May 11, 2020 · 0 comments

Comments

@imqiuhang
Copy link

------原文-----
类方法
类方法中不能直接调用对象方法
实例方法:
实例方法中也可以调用类方法(通过类名)

感觉这里是写反了,首先
类可以调用实例定义的方法,当然必须得是NSObject中定义的实例方法,例如[ClassA copy], Class调用了实例方法copy,只是调用没有意义,IMP中的id传的是class,能调用的原因是因为类的元类的superClass最终指向的是NSObject(也就是实例的isa最终指向的),也就是文章中发的那个图,所以是能找到对应的实例方法。
实例调用class方法严格来说也不正确,因为你调用的[[a class] func],调用func的其实是[a class],也就是a的class而并非实例a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant