Cocoa NSArray/NSSet: -makeObjectsPerformSelector: vs. fast enumeration

后端 未结 5 1045
臣服心动
臣服心动 2021-02-13 09:50

I want to perform the same action over several objects stored in a NSSet.

My first attempt was using a fast enumeration:

for (id item in myS         


        
5条回答
  •  旧时难觅i
    2021-02-13 10:38

    I too was presented with this question. I find in the Apple docs "Collections Programming Topics" under "Sets: Unordered Collections of Objects" the following:

    The NSSet method objectEnumerator lets you traverse elements of the set one by one. And themakeObjectsPerformSelector: and makeObjectsPerformSelector:withObject: methods provide for sending messages to individual objects in the set. In most cases, fast enumeration should be used because it is faster and more flexible than using an NSEnumerator or the makeObjectsPerformSelector: method. For more on enumeration, see “Enumeration: Traversing a Collection’s Elements.”

    This leads me to believe that Fast Enumeration is still the most efficient means for this application.

提交回复
热议问题