I just started learning Swift and came across function types and how to return them. I just want to know what the () means in the return value of function calcDecrement? I know the function returns a reference to the inner function decrementer so is the () return type for a function?     
func calcDecrement(forDecrement total: Int) -> () -> Int {
    var overallDecrement = 0
    func decrementer() -> Int {
        overallDecrement -= total
        return overallDecrement
    }
    return decrementer
}
let decrem = calcDecrement(forDecrement: 30)
print(decrem())
() -> Int is the return type and this represents a function that takes no arguments and returns an Int as the result.
decrementer matches this exactly, so it is good as a function to return.
If the return type took an Int as a parameter, then the return type would be (Int) -> Int.
See Apple’s documentation at The Swift Programming Language for more details about the type of a function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With