Error wanting to show an NSNumber value as Integer in a string

0

I have the following and it throws me an incompatible error integer to pointer ...

int *v = [numero intValue];
NSLog(@"Numero %d",v);

Where number is a NSNumber . How would you do to print a int ? And a NSInteger ?

    
asked by Popularfan 12.12.2016 в 13:53
source

1 answer

3

I understand that numero is declared as NSNumber with something of this style:

@property (strong, nonatomic) NSNumber  *numero;

And what you want is to assign it to i which is a int .

The problem is that NSNumber is an object and the variable i is a int that is a primitive type. This means that numero will be a pointer to some place in the memory, that's why the * in the declaration, but i is not an object, so you do not need the * in the declaration.

If you do this, it will work properly for you:

int i = [self.numero integerValue];
NSLog(@"numero %d", i);
    
answered by 12.12.2016 / 18:55
source