Map a void (non-returning function) over an array

前端 未结 1 1660
粉色の甜心
粉色の甜心 2021-01-14 04:26

Title is self-explanatory, is there any way of mapping, for example, addGestureRecognizer over an array of UIGestureRecognizers. I\'ve been fiddlin

相关标签:
1条回答
  • 2021-01-14 04:58

    map is designed to return an array from another array that has had a given transformation applied to it (by transforming each element). Therefore naturally the function that you pass to it has to return the transformed element.

    In your case, you're not actually transforming the elements, you just want to use them in an argument of a function. To do this, you can use forEach.

    recognizers.forEach(MyWebOutlet.addGestureRecognizer)
    
    0 讨论(0)
提交回复
热议问题