search

Home  >  Q&A  >  body text

objective-c - enumerateObjectsUsingBlock in NSArray: What it mainly does.

In the process of looking at the source code, I saw that some methods used

enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop);

Then I did some operations in this method. Add the value to the array. What is the benefit of writing this way? What is its specific effect? ​​What is the difference between it and the for loop and the for in loop?

仅有的幸福仅有的幸福2794 days ago870

reply all(2)I'll reply

  • 为情所困

    为情所困2017-05-16 13:20:34

    Array query, the efficiency advantage of small query is not very obvious, it is recommended to use forin. But for a large number of arrays, it is recommended to use enumerations

    Another one is to traverse the dictionary and it is recommended to use enumerations, so that you can get the key and value at one time

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 13:20:34

    You can operate on the array when traversing the array.
    If you use forin, it is easy to crash when operating on the array when traversing the array

    reply
    0
  • Cancelreply