This is my code:
@interface Object : NSObject {
@private
NSArray *array;
}
@property NSArray *array;
@end
And the @synthesize
in the implementation. I get a compiler warning in the line with the @property
:
warning: default assign attribute on property 'array' which implements NSCopying protocol is not appropriate with -fobjc-gc[-only]
If I write the property as @property (assign) NSArr开发者_开发知识库ay *array
it does not show up. What is this about?
In your case you are creating a property that is a pointer to an object. Assign, which is the default, is not appropriate for objects, which should be declared as retain
or copy
.
In your case you should define your property as:
@property (nonatomic, copy) NSArray *array;
You could use retain
instead of copy
here, but there are good reasons to use copy
.
edit
To answer the deeper question you seem to be asking - have a look at this thread from the Cocoa mailing lists.
Are you using the LLVM compiler or gcc?
Properties default to assign. Your property is an assign.
Regarding assign vs copy in GC enabled app, I found this via google...
http://www.cocoabuilder.com/archive/cocoa/194064-use-of-assign-vs-copy-for-accessors-in-garbage-collected-app.html
I think we usually use assign, but will use copy if needed, like for example, for NSString object. So to get rid of warning, we just explicitly specify it as assign.
精彩评论