Home > AI > IOS >

closure variable

Example 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct Example {
    let run: (Int) -> (String) // type declaration
}
 
extension Example {
    init(){
        // define
        self.run = { i in
            return "good, " + String(i)
        }
    }
}
 
 
let e = Example() // e.run is defined
e.run(90) // e.run can be used

Leave a Reply