ChenYilong / ChenYilong/iOSInterviewQuestions
第7题,重写copy属性setter方法,建议先加响应copyWithZone:的判断
Open
- Dominant language
- Swift
- Stars
- 9.5k
- Forks
- 2.8k
- PR merge metrics
- No merged PRs in 30d
Description
博主您好,首先非常感谢您能整理出这么优秀的内容,帮助大家学习!万分感谢!
然后在第七题的第二个问中:“如何重写带 copy 关键字的 setter”,个人认为,最好在
````
_name = [name copy];
````
之前再加一个对copyWithZone:响应的判断,如:
````
if ([name respondsToSelector:@selector(copyWithZone:)]) {
_name = [name copy];
}
````
不然如果真的有童鞋在使用的过程中传入一个没有服从NSCopying协议的对象,例如UIView什么的(即使有黄色警告,但如果被忽略掉的话。。。),就会造成崩溃。
您认为呢?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.