Convert NSNumber to NSString Problem

I know this is a problem that has already been asked a thousand times, but from the few published examples that I tried, I still run into problems.

Now I'm trying to display a value in my debug log of an object that contains the data that I need as NSNumber. I tried to use the following line of code:

NSString *distanceString = [NSString stringWithFormat:@"%d", (NSNumber)self.selectedBeacon.distance ];

However, with the above, I get the following error:

The type used is 'NSNumber' where arithmetic or pointer type is required

So, I tried the following:

NSString *distanceString = [NSNumber self.selectedBeacon.distance];

But when I approached the type self.selectedBeacon.distance, the line did not appear in my intelisense. So for my third attempt, I tried the following line:

NSString *distanceString = [NSString stringWithFormat:@"%d", [NSNumber self.selectedBeacon.distance]];

But I get the error:

Expected ']'

, , . - ?

+4
4

, self.selectedBeacon.distance NSNumber, [NSNumber stringValue] :

NSString *distanceString = [self.selectedBeacon.distance stringValue];
+12

.

NSString *distanceString = [NSString stringWithFormat:@"%d",[self.selectedBeacon.distance integerValue]];
+6

NSNumber - . .

NSNumber , :

NSString *numberAsString = [myNSNumber stringValue];
+1

NSLog,

NSLog(@"%@",self.selectedBeacon.distance);

description of self.selectedBeacon.distance .

0

Source: https://habr.com/ru/post/1525030/


All Articles