Skip to content

Instantly share code, notes, and snippets.

@Ochornma
Created May 15, 2021 14:41
Show Gist options
  • Save Ochornma/1e93b135201e999d69b3b6f85d148990 to your computer and use it in GitHub Desktop.
Save Ochornma/1e93b135201e999d69b3b6f85d148990 to your computer and use it in GitHub Desktop.
let plus: (Int, Int) -> Int = {
return $0 + $1
}
let minus: (Int, Int) -> Int = {
return $0 - $1
}
let add: (Int, Int) -> Int = {
return $0 + $1
}
let subtract: (Int, Int) -> Int = {
return $0 - $1
}
let closureFunctions = [ plus, minus ]
let plusSign = closureFunctions[0]
print(plusSign(1, 5))
//result is:
//6
//The append method
closureFunctions.append(add)
closureFunctions.append(subtract)
print(closureFunctions.count)
//result is:
//4
for closure in closureFunctions {
print(closure(6,5))
}
//result is:
//11
//1
//11
//1
let addition: (Int, Int) -> Int = {
return $0 + $1
}
let subtraction: (Int, Int) -> Int = {
return $0 - $1
}
let closureFunctions2= [ addition, subtraction ]
let newClosureFunction = closureFunctions + closureFunctions2
print(newClosureFunction.count)
//result is:
//6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment