I have been messing around with a bit of code to try and get my head around pointers and memory management in objective-c. However, what I can’t seem to understand is that using this code:
hello *myHello = [[hello alloc] init];
NSString *string = @"Hello";
myHello.property = string;
does the NSString instance (@”Hello”) get passed as a parameter to the setter method or does the pointer get sent. For example if I changed “string” to point to a different object and then got the variable would it still be “Hello” or change to the new object that “string” pointed to?
Thanks in advance!
When you do:
If property is defined without copy, it is set to point to the same place that string points to.
If property is defined with copy, it is set to point to a new copy of the original string.
In either case, if you then change string to point to a different string (e.g. @”Goodbye”), property will still point to @”Hello”.