lundi 19 novembre 2018

[Objective-C++]Why assigning object to BOOL type variable is allowed in 64bit but not in 32bit

The following code in ViewController.mm, would be compiled successfully(without any warning or error) in 64 bit environment.

- (void)viewDidLoad {
    [super viewDidLoad];
    BOOL var = [[NSUserDefaults standardUserDefaults] objectForKey:@"foo"];
    NSLog(@"%d", var);
}

But when I change the running target to a 32 bit device(e.g, iPhone 5), it show me error like this:

 Cannot initialize a variable of type 'BOOL' (aka 'signed char') with an rvalue of type 'id _Nullable'

I do know this assignment is wroing, but why it allowed in first situation?

Aucun commentaire:

Enregistrer un commentaire