Swift Program To Create A Closure Function And Return A Value

Swift Program To Create A Closure Function And Return A Value

Swift Program To Create A Closure Function And Return A Value

// Swift program to create a 
// closure function and return a value

import Swift

// Define a closure
let AddNum = {
    (num1:Int, num2:Int) -> Int in
    return (num1 + num2)
}

// call the created closure
var sum = 0

sum = AddNum(10,20)

print("Sum is: ",sum)

Output

Sum is:  30

...Program finished with exit code 0
Press ENTER to exit console.
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment