On Dec 22, 2008, at 4:04 PM, Debajit Adhikary wrote:

Let's say I have a class called SomeClass with a string property name:

@interface SomeClass : NSObject{
   NSString* name;
}

@property (nonatomic, retain) NSString* name;

@end

I understand that name may be assigned a NSMutableString in which case this
will may to errant behavior.

(1) For strings in general, is it *always* a good idea to use the "copy"
attribute instead of "retain"?

No. This isn't a "one way or another" situation. It's really up to what you need. Having said that, there are good guidelines as to why you'd want to use one over the other. Look at the memory-management guidelines or search the archives.

(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?

Definitely. It will cost more cycles to copy the object vs. retain it. And, will use more memory. However, the performance and memory costs may not have any noticeable impact on your code. A profiler can tell you for sure.

___________________________________________________________
Ricky A. Sharp         mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to