I am working in a single view application.
Suppose,
I have a new Class called BigCars
. In this new class, I have
@property (nonatomic) int carID;
Now if I go to viewController.h and create a property : @property (nonatomic,strong) BigCars *myBigCar;
Finally, I go to viewController.m
and write self.myBigCar.carID = 1234
;
Then if I
NSLog(@"%i", self.myBigCar.carID), I GET A 0 in the console.
Why?
(Assume I did the imports properly)
EDIT:
Creating a small game to help myself learn more about objective C development. Its a basic text game and the first page I have a label that contains a number. This number is the payers HP (Hit points). I have a character class called Character.h
who has a
@property (nonatomic) int currentHealth;
In viewController.h
I declared @property (nonatomic,strong) *myCharacter;
-> I did this because I want to be able to use this object throughout the whole implementation file.
In viewcontroller.m
, I want to set my label to this current health by writing :
// Create char
self.myCharacter.currentHealth = 89;
// Set labels and buttons
self.healthLabel.text = [NSString stringWithFormat:@"%i", self.myCharacter.currentHealth];
but for some reason, self.myCharacter.currentHealth
does not set to 89 but is instead 0!