convert NSArray of NSString(s) to NSArray of NSMutableString(s)

前端 未结 3 2091
长情又很酷
长情又很酷 2021-01-26 06:35

How to do that without having to \"scroll\" the entire given array with a \"for\" loop?

3条回答
  •  没有蜡笔的小新
    2021-01-26 07:03

    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"];
    

    From the docs:

    valueForKey:
    Returns an array containing the results of invoking valueForKey: using key on each of the array's objects.

    - (id)valueForKey:(NSString *)key

    Parameters
    key The key to retrieve.

    Return Value
    The value of the retrieved key.

    Discussion
    The returned array contains NSNull elements for each object that returns nil.

提交回复
热议问题