Objective-C中是否有通用功能,我可以插入到我的项目中以简化连接NSString
和int
s?
[NSString stringWithFormat:@"THIS IS A STRING WITH AN INT: %d", myInt];
这通常是我如何做到的.
两个答案都是正确的.如果要连接多个字符串和整数,请使用NSMutableString的appendFormat.
NSMutableString* aString = [NSMutableString stringWithFormat:@"String with one int %d", myInt]; // does not need to be released. Needs to be retained if you need to keep use it after the current function. [aString appendFormat:@"... now has another int: %d", myInt];