迭代包含字符串的 NSMutableArray
我将字符串添加到 NSMutableArray 中,现在我想迭代该数组:
NSEnumerator *e = [numbers objectEnumerator];
id object;
NSMutableString* theString = [NSMutableString string];
while (object = [e nextObject]) {
[theString appendString:[NSString stringWithFormat:@"%i;", object]];
}
但实际上 object 似乎不是我添加到数组中的字符串,而只是一个数字。我怎样才能得到字符串?
I add strings to an NSMutableArray and now I want to iterate that array:
NSEnumerator *e = [numbers objectEnumerator];
id object;
NSMutableString* theString = [NSMutableString string];
while (object = [e nextObject]) {
[theString appendString:[NSString stringWithFormat:@"%i;", object]];
}
But actually object does not seem to be the string I added to the array but just a number. How can I get the string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需附加字符串即可。无需(昂贵的)格式转换。
Just append the string. No need for (expensive) format conversion.
"%i"
是整数的格式字符串,因此它将对象的地址视为整数。对象的格式为"%@"
。"%i"
is the format string for an integer, so it's treating the object's address as an integer. The format for an object is"%@"
.