Home > AI > IOS >

closure variable

Example 1:

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