Objective-C NSString Reference Types

前端 未结 8 1254
情歌与酒
情歌与酒 2021-01-14 17:35

I have a simple question. If I am declaring NSString (ref type) as shown below:

 NSString *johnsMoney = @\"200\";
    NSString *marysMoney = johnsMoney;

           


        
8条回答
  •  礼貌的吻别
    2021-01-14 18:21

    They are not references. They are object pointers. If two variables happen to point to the same object, changing one pointer to point to another object has no effect on the other pointer.

    Think of two people standing near each other. Both hold out an arm and point to the same table. Now one person turns and points to a chair. The other person isn't affected. They are still pointing to the table.

提交回复
热议问题