For non-retained string declarations, are these three lines the same?
NSString *list2 = self.map;
NSString *list2 = [NSString stringWithFormat:@"%@", self.map];
NSString *list2 = [NSString stringWithString:self.map];
They all create an autoreleased string object, right? Is there a preferred method among these, or are there any differences in the memory usage or behavior of “list2” depending on these methods?
For some reason, I find the manipulation of strings in objective-C the most confusing transition from other languages.
No, the first one merely assigns the pointer returned by
string.maptolist2. The second and third ones theoretically create newNSStringsthat you don’t own and assign them tolist2. However, ifstring.mapreturns an immutable string, the third one will probably give you the same pointer (possibly retained and autoreleased).In all cases you do not own the (new) string. That’s actually all you need to know. They may be autoreleased, but it is not relevant to you using them.