First, by convention, class names in Objective C have the first capital letter.
In most cases, it is not necessary to synthesize ownership. The compiler will automatically generate the instance variable. Ex: When declaring @property (strong) NSString *marca;
the compiler will automatically generate the instance variable _marca
. The instance variable is only accessible in the class implementation. Access to the property depends on the modifiers in the declaration: readonly, readwrite (default).
Here is an example:
Car.h
@interface Carro : NSObject
@property (copy, nonatomic) NSString *marca;
@property (copy, nonatomic) NSString *modelo;
@property (assign, nonatomic) NSUInteger ano;
@end
Car.m
@implementation Carro
- (instancetype)init {
self = [super init];
if (self) {
_marca = @"VW";
_modelo = @"Fusca";
_ano = 1979;
}
return self;
}
@end
ViewController.m
//Exemplo de utilização da classe Carro
@implementation ViewController {
Carro *carro;
}
- (void)methodA {
carro = [Carro new];
NSLog(@"%@ %d", carro.modelo, carro.ano);//Fusca 1979
[self methodB];
}
- (void)methodB {
[carro setAno:2014];
[carro setModelo:@"Gol"];
NSLog(@"%@ %d", carro.modelo, carro.ano);//Gol 2014
}
If you are in doubt as to the concepts of object orientation and MVC I suggest you study these topics before deepening your studies in Objective C.