Implementation in Car class objective-C

Asked

Viewed 75 times

1

I have this code and I would like to know if this way of implementing is valid in objective-C.

@interface Carro : NSObject

@property (copy, nonatomic) NSUInteger ano;
@property (copy, nonatomic) NSString *modelo;
@property (assign, nonatomic) NSUInteger ano;
@property (assign, nonatomic) NSUInteger qtdGasolina;
@property (assign, nonatomic) NSUInteger marchaAtual;

@end

1 answer

1

You have set the year property twice. The correct form is using the modifier assign. Is used copy on objects that have a mutable counterpart, such as Nsstring - Nsmutablestring and Nsarray - Nsmutablearray.

For example, given the following code:

NSMutableString *modelo = [[NSMutableString alloc] initWithString:@"Fusca"];
Carro *carro = [Carro new];
carro.modelo = modelo;
[modelo setString:@"Kombi"];

If the attribute model were defined as assign, When modifying the String to Kombi, the value of the attribute of the Car object would also change, which is not generally expected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.