In BNR iOS book the authors say to make this copy
instead of strong
:
@property (nonatomic, copy) NSString *itemName;
But I don't really understnad the purpose because in the main
method I tried out:
BNRItem *calculator = [[BNRItem alloc] init];
NSString *pickle = @"pickbarn";
backpack.itemName = pickle;
pickle = @"fuffle";
When I printed out backpack
's name to the console it was picklebarn
, so I don't really understand why itemName
needs to be copied
?
Because it's possible that a mutable string could be passed in.
(Also, IIRC, -copy
on an immutable string just retains it under the hood.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With