1、NSNumber转NSString
NSNumber *number = @(YES); if(number && [number isKindOfClass:[NSNumber class]]) { //若考虑为空或NSString类型的情况,该方法兼容性比较好 NSString *String = [NSString StringWithFormat:@"%@",number]; //或者 该方法一定要判断类型不然可能闪退 // NSString *String = number.description; }
NSString字符串如何转为NSNumber
2、NSString 转 NSNumber
NSString *str = @"327691"; NSNumber *number = nil; if(str) { number = @(0); } else if([str isKindOfClass:[NSString class]]) { // 字符串先转成long long类型,再转对象 number = @([str longLongValue]); }