Joined June 2014
·

Russell Finn

Senior Mac OS X Engineer at Vera
·
Mount Airy, MD
·
·
·

Posted to forEach on an Array in Swift over 1 year ago

As of Swift 2, forEach(_:) is a builtin method on SequenceType objects, so you don't need to define an extension on Array.

On the other hand, it is more usual in Swift to iterate directly on the Array:

for item in items {
    if item.someProperty {
        doCoolStuff()
    }
}

The code without the typedef needs to have the return type specified as void (to match the example that uses the typedef):

@property (nonatomic, copy) void (^myActionBlock)();

Personally in this case I'd consider using a typedef, unless I was making a framework or other shared code and wanted to avoid introducing too many symbols into the shared namespace.

Achievements
1 Karma
0 Total ProTip Views
Interests & Skills