Reputation: 4244
I was just going through this blog from Mikeash and found the following declaration:
private let f: AnyObject -> Parameters -> Void
I am not clear what this syntax means. I tried looking into Swift Programming Guide but was not able to find any answer.
Can someone please put some light on it, possibly some reference?
Upvotes: 1
Views: 84
Reputation: 3518
See the Swift Programming Language Reference, Chapter Types, title Function Types:
The function types of a curried function are grouped from right to left. For instance, the function type
Int -> Int -> Int
is understood asInt -> (Int -> Int)
— that is, a function that takes an Int and returns another function that takes and return an Int. Curried function are described in Curried Functions.
(I formatted the code parts)
See here for an explanation about curried functions.
Upvotes: 3
Reputation: 16770
Basically the type of f
is a function which takes AnyObject
as its parameter and returns a function which type is Parameters -> Void
(takes Parameters
as parameter and returns Void
). Perhaps this code below will help you understand it.
func makeIncre(n:Int) -> Int -> Int {
func addN(a:Int) -> Int{
return a + n
}
return addN
}
let addOne = makeIncre(1)
let addTwo = makeIncre(2)
addOne(6) // 7
addTwo(6) // 8
Upvotes: 0