直接将NSNumber转换为NSString

时间:2014-02-13 15:13:45

标签: ios objective-c nsstring nsnumber

如何?

·H

@property (nonatomic, strong) NSNumber *seasonRoundN;
@property (nonatomic, strong) NSString *seasonRound;

的.m

_weMeetAgain = [NSNumber numberWithInt:13];
_seasonRound = [NSString stringWithFormat:_weMeetAgain]; // incompatible :S

应该更好地查看参考文献:(以下答案)

_weMeetAgain = [NSNumber numberWithInt:17];
_seasonRound = [NSString stringWithFormat:@"%@", _weMeetAgain];

帮助:P,谢谢。

2 个答案:

答案 0 :(得分:5)

[NSString stringWithFormat:@"%d", [_weMeetAgain intValue]]

答案 1 :(得分:5)

只需使用NSNumber实例方法stringValue

_seasonRound = [_weMeetAgain stringValue];