ghostrider
ghostrider

Reputation: 5259

cannot assign a value on a custom NSObject

I am probably missing or not seeing something very basic but I can't debug it anymore.

Here is my code :

NSLog(@"Joker Selected : %d, Prio Value is :%@",joker,[LBGameData sharedGameData].round.joker_1_used ? @"true" : @"false");
[LBGameData sharedGameData].round.joker_1_used = TRUE;
NSLog(@"End of selection, Prio Value is :%@",[LBGameData sharedGameData].round.joker_1_used ? @"true" : @"false");

Here is the definitions.

LBGameData

@property (strong, retain) LBGameRound* round;
+(instancetype)sharedGameData;

LBGameRound

@property (assign, nonatomic) BOOL joker_1_used;

This is my output :

2015-10-18 18:54:01.478 Game[804:298953] Joker Selected : 1, Prio Value is :false
2015-10-18 18:54:01.479 Game[804:298953] End of selection, Prio Value is :false

Why I can't see the true in the second output, although i set it on the line above?

Upvotes: 0

Views: 47

Answers (2)

Jamil
Jamil

Reputation: 2999

Try by the following way.

  BOOL joker_1_used = [LBGameData sharedGameData].self.round.joker_1_used =TRUE;
  NSLog(@"End of selection, Prio Value is :%@",joker_1_used? @"true" : @"false");

Output:

 End of selection, Prio Value is :true

Upvotes: 0

rmaddy
rmaddy

Reputation: 318814

Given the output, the most likely issue is that either [LBGameData sharedGameData] or [LBGameData sharedGameData].round are nil.

Trying to access the BOOL value from the nil value will result in a NO value resulting in the output you are seeing.

Upvotes: 1

Related Questions