Answers for "map in swiftui"

0

map swift

// A map example which maps each item in  this array of numbers
// to its value multiplied by 2.

let array = [1, 2, 3, 4]

// Full closure
print(array.map({ (num: Int) -> Int in return num * 2 }))

// Abbreviated trailing closure, with inferred arguments, 
// argument type, and return type.
print(array.map { $0 * 2 })

// Output: [2, 4, 6, 8]
Posted by: Guest on December-23-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language