János
János

Reputation: 35090

How to define array of closures in Swift?

I want to define like this:

public var reloadFRCsNeedToPerformWhenFail = [()->()]()

but I get an error

enter image description here

Upvotes: 11

Views: 7336

Answers (1)

matt
matt

Reputation: 535511

Like this:

public var reloadFRCsNeedToPerformWhenFail : [()->()] = []

If you use a type alias to make ()->() a type, you can do it your way:

public typealias VoidVoid = ()->()
public var reloadFRCsNeedToPerformWhenFail = [VoidVoid]()

Or, forego the [] shortcut notation and use the full generic:

public var reloadFRCsNeedToPerformWhenFail = Array<()->()>()

Upvotes: 26

Related Questions