如何制作自定义对象的副本
我创建了一个继承自 NSObject 的自定义对象。假设我有一个由这些对象组成的数组。然后我想创建另一个对象,即数组中一个对象的副本。我不想简单地指向数组中的现有对象,我想要一个副本。有没有简单的方法可以做到这一点?
I made a custom object that inherits from NSObject. Let's say I have an array of these objects. Then I want to make another object, that is a copy of one of the objects in the array. I do not want to simply point to an existing object in the array I want a copy. Is there an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现
NSCopying
,并按如下方式使用它:请注意,此时
theCopy
是一个保留的对象,当您使用完它时应该将其释放。Implement the
NSCopying
protocol on the object, and use it as follows:Note that
theCopy
is a retained object at this point, and should be released when you are done with it.