Rafał
Rafał

Reputation: 1287

Property attributes in custom setters/getter

If I create property, for example:

@property NSString *selectedSubProductId;

and create setter and getter:

- (NSString *)selectedSubProductId {}

- (void)setSelectedSubProductId:(NSString *)value_ {}

XCode says that "Deault property attribute 'assign' not appropriate for non-gc object". Do attributes have any meaning in this case? Does it matter if i make them copy or assign or are they only cue for @synthesize to create desired methods? If so, how should I disable the warnings?

Upvotes: 1

Views: 1348

Answers (2)

Tiago Almeida
Tiago Almeida

Reputation: 14237

That warning says that you are using a default property atribute (assign) because you forgot to say how do you want to hold your object.

If you want to "remove" the warning use a retain/copy property: @property (copy) NSString *selectedSubProductId;

However, in Strings you should use copy. For more information please visit this question on stackoverflow.

Upvotes: 0

HKTonyLee
HKTonyLee

Reputation: 3310

If it is object, you should use retain/copy property modifier.

For example:

@property (nonatomic, retain) NSString *selectedSubProductId;

If the modifiers are missing, assign modifier is enabled by default. But it is only valid for scalar (int, float...) or struct.

You may get more details in Apple Documentation

Upvotes: 1

Related Questions