Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 656
János Avatar asked Apr 23 '15 16:04

János


1 Answers

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<()->()>()
like image 177
matt Avatar answered Oct 13 '22 23:10

matt