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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…