iPhone : (id)copyWithZone:(NSZone *)zone : what is “zone” for?

狂风中的少年 提交于 2019-12-03 11:20:22
Lily Ballard

It's a relic from the old days, where we had multiple "zones" to allocate in. These days, all apps only have a single zone where all allocations are made, but the NSZone class still exists and far too much code is written to depend on +allocWithZone: being the fundamental allocation method to make the change.

In short, you can ignore the NSZone struct in its entirety, and the only reason to care about +allocWithZone: is if you need to override it. Similarly with -copyWithZone:, you can just ignore the zone. If you so desire, you can call +allocWithZone: passing in the same zone, but it won't make any difference.

Have a look over the NSCopying Protocol Reference, specifically copyWithZone:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!