First, by convention, class names in Objective C have the first capital letter.
In most cases, it is not necessary to synthesize the property. The compiler will automatically generate the instance variable. Ex: when declaring @property (strong) NSString *marca;
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).
Follow 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 about the concepts of object orientation and MVC I suggest you study these topics before deepening the studies in Objective C.