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

第7题,重写copy属性setter方法,建议先加响应copyWithZone:的判断 #105

Open
XTShow opened this issue May 27, 2018 · 0 comments

Comments

@XTShow
Copy link

XTShow commented May 27, 2018

博主您好,首先非常感谢您能整理出这么优秀的内容,帮助大家学习!万分感谢!

然后在第七题的第二个问中:“如何重写带 copy 关键字的 setter”,个人认为,最好在

_name = [name copy];

之前再加一个对copyWithZone:响应的判断,如:

if ([name respondsToSelector:@selector(copyWithZone:)]) {
        _name = [name copy];
    }

不然如果真的有童鞋在使用的过程中传入一个没有服从NSCopying协议的对象,例如UIView什么的(即使有黄色警告,但如果被忽略掉的话。。。),就会造成崩溃。
您认为呢?

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