【问题标题】:Straight up convert NSNumber to NSString [duplicate]直接将 NSNumber 转换为 NSString [重复]
【发布时间】:2014-03-12 13:25:03
【问题描述】:

怎么做?

.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,谢谢。

【问题讨论】:

  • _seasonRoung = [_weMeetAgain stringValue];

标签: ios objective-c nsstring nsnumber


【解决方案1】:
[NSString stringWithFormat:@"%d", [_weMeetAgain intValue]]

【讨论】:

    【解决方案2】:

    只需使用 NSNumber 实例方法stringValue

    _seasonRound = [_weMeetAgain stringValue];
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 2010-11-29
      • 1970-01-01
      相关资源
      最近更新 更多