Mik*_*keN 8 objective-c nsnumber nsmutablearray nsmutabledictionary
你如何"int"在一个NSMutableArray或多个存储值NSMutableDictionary?JSON数据的慢性问题以整数形式出现.
我应该尝试将这些整数存储为NSNumber对象还是作为包含整数的字符串存储?
如果我知道值将始终为自然数(数字> = 0,包括零为零),那么对指针执行"原始"(int)转换有多危险.
我一直在使用的整数是来自数据库的外键ID.
the*_*ent 23
像这样使用NSNumber:
int yourInt = 5;
[myMutableArray addObject:[NSNumber numberWithInt:yourInt]];
Run Code Online (Sandbox Code Playgroud)
或者使用现代Objective C语法,您可以使用以下表达式:
[myMutableArray addObject:@(2 + 3)];
Run Code Online (Sandbox Code Playgroud)
或者对于单个数字:
[myMutableArray addObject:@5];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14553 次 |
| 最近记录: |