Implementation in class C-objective Car

1

I have this code and would like to know if this implementation 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
    
asked by anonymous 09.04.2015 / 00:34

1 answer

1

You have set the year property twice. The correct way is by using the assign modifier. copy is used 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 template attribute was set to assign , by modifying the String to Kombi, the car attribute value would also change, which is not usually the expected.

    
09.04.2015 / 01:10