开发者

How do I copy an object value from a mutable array into a string?

开发者 https://www.devze.com 2023-02-03 11:24 出处:网络
How do I copy an object value from a mutable array into a string? The array holds objects from parsed XML, but now I cannot copy the array value into a string.

How do I copy an object value from a mutable array into a string?

The array holds objects from parsed XML, but now I cannot copy the array value into a string.

How can I do th开发者_开发知识库is?


NSNumber has a stringValue message, which returns the object as an NSString:

NSString *foo = [myNSNumber stringValue];

Alternately, if you have a primitive value like NSUInteger, or a float, you can use NSString directly:

NSUInteger nsuint = 20;
CGFloat fff = 21.0;

NSString *foo = [NSString stringWithFormat:@"%ld",(long)nsuint];

//or

NSString *foo = [NSString stringWithFormat:@"%f",fff];

Ole's question stands, however. One way to find out might be to iterate through the array asking for descriptions:

int count = 0;
for (id item in myMutableArray) {
    count +=1;
    NSLog(@"Item %d is a %@", count, [item description]");
}

This doesn't always yield intelligent results, but often does.

0

精彩评论

暂无评论...
验证码 换一张
取 消