Objective-C NSString Reference Types

前端 未结 8 1358
情歌与酒
情歌与酒 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:30

    No. Remember you are dealing with pointers. So when you do

    johnsMoney = @"100";
    

    You are setting the johnsMoney pointer to a different memory address which contains the @"100" value. marysMoney still points to the original address with the @"200" value.

提交回复
热议问题