objective c - 如何將NSNumber轉換為NSString

objective-c nsarray (5)

在Swift 3.0中

let number:NSNumber = 25
let strValue = String(describing: number as NSNumber)
print("As String => \(strValue)")


所以我有一個帶NSNumber s和NSString s的NSArray “myArray”。 我需要他們在另一個UIView所以我走這樣:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

DetailViewController *details = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
details.subjectText = [[myArray objectAtIndex:indexPath.row] objectForKey:@"subject"];

主題文本的作品。 但是我怎樣才能從中獲得NSNumber呢? (我實際上需要它們作為字符串...)我會將NSStringNSNumber轉換出來,如下所示: NSString *blah = [NSNumber intValue] 。 但我不知道如何在上面的代碼中設置它...


NSNumber *myNumber = @15;
NSString *myNumberInString = [myNumber stringValue];


let number : NSNumber = 95
let str : String = number.stringValue

或者嘗試NSString *string = [NSString stringWithFormat:@"%d", [NSNumber intValue], nil];

//An example of implementation :
// we set the score of one player to a value
[Game getCurrent].scorePlayer1 = [NSNumber numberWithInteger:1];
// We copy the value in a NSNumber
NSNumber *aNumber = [Game getCurrent].scorePlayer1;
// Conversion of the NSNumber aNumber to a String with stringValue
NSString *StringScorePlayer1 = [aNumber stringValue];