ios - object-c 对象拷贝的问题
ringa_lee
ringa_lee 2017-04-17 16:06:17
0
1
326

我怎样拷贝一个一模一样的对象呀,这个对象是我自定义的。

什么浅复制深复制,我用copy好像不行。

我希望有个这样的功能给我

[[NSArray alloc] initWithArray:<#(nonnull NSArray *)#>]

ringa_lee
ringa_lee

ringa_lee

reply all(1)
巴扎黑

copy can only be used if the nscoping protocol is extended

General
NSString NSMutebleString
NSArray NSMutebleArray
NSDictionary NSMutebleDictionary
NSSet NSMutebleSet
These capabilities
The former is read-only and the latter can be modified
read-only -> read-only 只读 -> 只读

NSArray *a = [NSArray array];
NSArray *b = [a copy];

a b 浅拷贝 地址一样的 只读 复制一份 其实执行的retain 没必要创建新对象

只读 -> 可修改 用mutablecopy
可修改 -> 可修改 用mutablecopy
可修改 -> 只读 用copy
这些都是深拷贝 rrreee

a b Shallow copy The address is the same. Read-only. Make a copy. In fact, there is no need to create a new object when executing retain

Read-only-> Modifiable Use mutablecopy🎜Modifiable-> Modifiable Use mutablecopy🎜Modifiable-> Read-only Use copy🎜These are deep copies that will create objects🎜 🎜Is your NSarray read-only copy or read-only, so it is a shallow copy🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template