我是的新手Swift ,我正在尝试声明一个接收回调的函数。

func getAll(callback: (students: [Student]!) -> Void) {
    // http request to get a list of students and parse it

    callback(students: students)
}

当调用该函数时,我在做:
obj.getAll() {
    (students: [Student]!) in

    // Callback code
}

但是它不会建立,它说:Cannot invoke getAll with an argument list of type '(([Student]!) -> _)'
我以this thread为指导,我错过了什么?

最佳答案

struct Student {

}

func getAll(callback: (students: [Student]!) -> Void) {
    // http request to get a list of students and parse it
    let students = [Student]()

    callback(students: students)
}

getAll { (students) -> Void in
    println(students)
}

关于ios - Swift回调语法问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29905359/

10-13 03:49