foreach Using Objective-C Generics
Peter Steinberger shares an Objective-C macro that lets you write foreach (object, collection)
, where object
gets the proper type based on the collection’s type parameter. The benefits: you save space and typing vs. a standard for
loop, yet you still get static checking and auto-completion. The code ends up looking like my macro from the old days before NSFastEnumeration
and for…in
loops.
Update (2017-05-15): Peter Steinberger:
I wrote a header that overrides mutable/Copy to pass along types+generic type data in Objective-C.