closure swift
// The basic closure syntax is:
// { (parameter: Type) -> Type in <statements> }
//
// While closures can be assigned to a variable like in
// the example below, they become much more useful once
// they're passed into a function such as a list's `filter`
// method.
let closure = { (a: Int, b: Int) -> Int in return a * b }
print(closure(3, 6)) // 18
print(closure(10, 2)) // 20
Are there any code examples left?
New code examples in category Swift
-
Swift 2022-03-27 22:55:05 swift sleep milliseconds
-
Swift 2022-03-27 20:20:18 swift how to call a function
-
Swift 2022-03-27 15:40:24 swift loop through array
-
Swift 2022-03-27 08:15:23 swift image button blue
-
Swift 2022-03-25 04:15:09 Finger Print in Swift
-
Swift 2022-03-25 03:20:26 swift save data to file
-
Swift 2022-03-24 14:45:28 change textview link color swift
-
Swift 2022-03-19 13:45:01 swift uitextfield only numbers keyboard lock programmatically
-
Swift 2022-03-18 01:25:20 how to read music library from iphone programmatically in swift