如何在更改后更新NSString属性/变量?

时间:2012-11-20 10:02:00

标签: iphone objective-c ipad

我对iOS开发者网站上的某些项目感到困惑,需要解释。在下面的情况A,B中,属性/变量将会更新,但事实并非如此。 The page where the below code居住。

这些是属性/变量

  • A)self.badgeView.firstName
  • B)NSDate *originalDate

这是代码的两个片段:

NSMutableString *nameString = [NSMutableString stringWithString:@"John"];   
self.badgeView.firstName = nameString; 
[nameString appendString:@"ny"];
NSDate *originalDate = self.lastModificationDate;
self.lastModificationDate = [NSDate date]; 
NSLog(@"Last modification date changed from %@ to %@", originalDate, self.lastModificationDate);

1 个答案:

答案 0 :(得分:3)

这些NSString属性,如果实施正确方法,将复制您传递的参数。

NSMutableString *nameString = [NSMutableString stringWithString:@"John"];   
self.badgeView.firstName = nameString; 
[nameString appendString:@"ny"];
// you'll have to update it again, if you want that view's string updated:
self.badgeView.firstName = nameString;