在iOS中将int转换为字符串的更好方法

Jin*_* Xu 0 objective-c nsstring ios ios7

我想知道是否有更好的方法将int转换为字符串基本上我有一个计数器和一个字典

//
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
int cnt = 0;
//
// insert an object
//
id object = [[[SomeObject alloc] init] autorelease];
NSString *key = [NSString stringWithFormat:@"%d", cnt++];
[dict setObject:object forKey:key];
Run Code Online (Sandbox Code Playgroud)

将int转换为字符串需要的时间比我预期的要长.那么有更好的解决方法吗?

Chr*_*sCM 6

我想这速度要快得多:

NSString* yourString = [@(yourInteger) stringValue];  
Run Code Online (Sandbox Code Playgroud)

还有这个

[dict setObject:yourObj forKey:[@(yourInt) stringValue]];
Run Code Online (Sandbox Code Playgroud)

看起来比以下更好:

[dict setObject:yourObj forKey:[NSString stringWithFormat:@"%d",yourInt]];
Run Code Online (Sandbox Code Playgroud)

但是从速度和风格的角度来看,我们真的在这里分裂.