1

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 this?

2
  • 2
    What class are the objects in the array? Commented Jan 6, 2011 at 21:41
  • Some code where we can see what you are trying to do may also be helpful. Commented Jan 6, 2011 at 22:31

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've edited the format specifiers to be consistent across 32-64 bit environments as described in the String Programming Guide

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.