iPhone:复制/克隆
我想复制或克隆我自己编写的类的对象。 但如果我调用复制函数,则仅复制指针。因此,如果我更改复制的对象,原始对象也会更改。
有没有一种方法/功能可以真正克隆一个对象?
此致 梅兰妮
I want to copy or clone a object of my own written class.
But if I call the copy function only the pointer were copied. So if I change the copied object the original object is changed, too.
Is there a way/function to really clone an object?
best regards
Melanie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所追求的被称为“深层复制”,您想要复制指针的内容,而不是它指向的地址。
下面有一些关于此列表的堆栈溢出问题:
另外,这里还有一个来自 Techtopia 的文章:此处
此处添加是我的 Google 搜索:这里
What you are after is refered to as Deep Copy, where you want to copy the contents of a pointer, not the address it points to.
There are a few stack overflow questions about this list Below:
Additionally here is a article from Techtopia: Here
Addition here is my Google Search: Here
如果对象的类采用 NSCopying 协议并实现其单一方法,则可以复制对象 copyWithZone:。
请参阅对象复制
An object can be copied if its class adopts the NSCopying protocol and implements its single method, copyWithZone:.
See Object copying