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

后端 未结 9 1945
北恋
北恋 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 05:04

    Its an old post but here's my view on the question

    Retain increases the retain count of an object by 1 and takes ownership of an object.

    Whereas copy will copy the data present in the memory location and will assign it to the variable so in the case of copy you are first copying the data from a location assign it to the variable which increases the retain count.

    Just remember that retain works on reference and copy works on value

提交回复
热议问题