What is the difference between “copy” and “retain”?

后端 未结 9 1933
北恋
北恋 2020-12-13 04:10

What is the difference between copy and retain for NSString?

- (void)setString:(NSString*)newString
{
    string = [ne         


        
9条回答
  •  感情败类
    2020-12-13 04:45

    if you use retain, it copy the pointer value from original one.retain also increment the reference count by one. but in case of copy, it duplicate the data referenced by the pointer and assign it to copy's instance variable.

提交回复
热议问题