I know this is an issue that is already been asked a thousand times but of the few posted examples I've tried, I'm stilling running into issues.
Right now I'm trying to display a value to my debug log of an object that holds the data I need as an NSNumber. What I was trying was the following line of code:
NSString *distanceString = [NSString stringWithFormat:@"%d", (NSNumber)self.selectedBeacon.distance ];
However, with the above I get the following error:
Used type 'NSNumber' where arithmetic or pointer type is required
So then I tried the following:
NSString *distanceString = [NSNumber self.selectedBeacon.distance];
But when I went to type self.selectedBeacon.distance
the line didn't appear in my intelisense. So for my third attempt I've tried the following line;
NSString *distanceString = [NSString stringWithFormat:@"%d", [NSNumber self.selectedBeacon.distance]];
But the error I get is this;
Expected ']'
Though I can see i have two closing brackets so that error has thrown me. Can anyone please help me on this?
Assuming self.selectedBeacon.distance
is an NSNumber
, then you can use [NSNumber stringValue]
to get a string representation:
NSString *distanceString = [self.selectedBeacon.distance stringValue];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With