Search code examples
objective-ciosnsarraymapreduce

NSArray. How do I implement the Map function?


In iOS I want to implement the map function for NSArray. This is a function that is applied to every element of the array. What is the best way to implement this?

Thanks,
Doug


Solution

  • You can use enumerateObjectsUsingBlock: function of NSArray.

    [myArray enumerateObjectsUsingBlock:^(id x, NSUInteger index, BOOL *stop) {
        // Body of the function
    }];