简体   繁体   中英

How can I update the NSString property/variable after it changed?

I am confused about some items on the iOS developer site and require explanation. In the below cases A, B the property / variable is going to get updated, but it doesn't. The page where the below code resides.

These are the property/variable

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

These are the 2 snippets of code:

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);

Those NSString properties, if implemented The Right Way , will copy the parameter you pass.

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; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM