So I have an NSArray
"myArray" with NSNumber
s and NSString
s. I need them in another UIView
so i go like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *details = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
details.subjectText = [[myArray objectAtIndex:indexPath.row] objectForKey:@"subject"];
The subjectText works.
But how can I get the NSNumber
s out of it? (I actually need them as strings...)
I would convert a NSString
out of a NSNumber
like this:
NSString *blah = [NSNumber intValue]
. But I don't know how to set it up in the code above...
The funny thing is that NSNumber converts to string automatically if it becomes a part of a string. I don't think it is documented. Try these:
It will print:
Works on both Mac and iOS
This one does not work:
In Swift you can do like this
or try
NSString *string = [NSString stringWithFormat:@"%d", [NSNumber intValue], nil];
In Swift 3.0
We can get the number value in String.
Try: