Cuckoo for Cocoa Dev

A blog for all those Cuckoo for Cocoa Development

Using Block Enumeration for Custom Collections

While the for-in loop is a great way to enumerate through collections such as NSArray, sometimes it’s lacking in other areas that force us to go back to using classical for() syntax. An easy example is the necessity of an index in said collection in addition to the object being enumerated. This is where block enumeration comes through to give us an easy way to traverse through the list as well as get other helpful information such as a stop variable, index in addition to the objects. While this is quite common, what developers tend to forget is that this block enumeration can also be added to custom objects and collections.