将 NSString(s) 的 NSArray 转换为 NSMutableString(s) 的 NSArray [英] convert NSArray of NSString(s) to NSArray of NSMutableString(s)
问题描述
如何在不必使用for"循环滚动"整个给定数组的情况下做到这一点?
How to do that without having to "scroll" the entire given array with a "for" loop?
推荐答案
因为似乎没有人同意我的评论,认为这是重复的 将 NSNumbers 的 NSArray 转换为 NSStrings 的数组的更好方法,这里再次给出相同的答案:
Since nobody seems to agree with my comment that this is a duplicate of Better way to convert NSArray of NSNumbers to array of NSStrings, here's the same answer again:
NSArray * arrayOfMutableStrings = [arrayOfStrings valueForKey:@"mutableCopy"];
来自 文档:
valueForKey:
返回一个包含调用结果的数组valueForKey:
在数组的每个对象上使用 key
.
valueForKey:
Returns an array containing the results of invokingvalueForKey:
usingkey
on each of the array's objects.
- (id)valueForKey:(NSString *)key
参数key
要检索的密钥.
返回值
检索到的键的值.
Return Value
The value of the retrieved key.
讨论
返回的数组包含每个返回 nil
的对象的 NSNull
元素.
这篇关于将 NSString(s) 的 NSArray 转换为 NSMutableString(s) 的 NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!