[英]How do I copy an object value from a mutable array into a string?
如何将对象值从可变数组复制到字符串中?
该数组保存来自已解析XML的对象,但是现在我无法将数组值复制到字符串中。
我怎样才能做到这一点?
NSNumber有一个stringValue消息,该消息将对象作为NSString返回:
NSString *foo = [myNSNumber stringValue];
或者,如果您具有NSUInteger之类的原始值或浮点数,则可以直接使用NSString:
NSUInteger nsuint = 20;
CGFloat fff = 21.0;
NSString *foo = [NSString stringWithFormat:@"%ld",(long)nsuint];
//要么
NSString *foo = [NSString stringWithFormat:@"%f",fff];
奥莱的问题仍然存在。 一种查找方法可能是遍历数组以获取描述:
int count = 0;
for (id item in myMutableArray) {
count +=1;
NSLog(@"Item %d is a %@", count, [item description]");
}
这并不总是产生明智的结果,但通常会产生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.