I have an NSArray
consisting of NSNumbers
and I want to convert this to an NSArray
of NSStrings
, by getting the str
NSArray
implements the Key-Value Coding method valueForKey: in such a way that it returns a new array. The new array contains the results of asking each object in the original array for the specified value. In this case, NSNumber
has its stringValue
, so all you have to do is:
NSArray * b = [a valueForKey:@"stringValue"];
Plain old fast enumeration (or enumerateObjectsUsingBlock:
) wouldn't be a terrible solution, though. NSArray
's implementation of valueForKey:
most likely uses a for
loop internally, and that would be pretty readily understood by anyone who reads it later.