Return 在 Swift 中使用闭包作为完成处理程序时的值

Return value while using closure as a Completion Handler In Swift

func loadMoreData(offset: Int, completion: (result: [ArtistJSONMapper]?) -> Void) {

    var fetchedData = [ArtistJSONMapper]()
    let pageNum: Int = offset/paging.limit

    // Calling the json fetch to obtain data

    JSONFetch.jsonTest() { (fetched, error) -> Void in
        if(fetched != nil) {
            fetchedData = fetched!
            //self.tableView.reloadData()

        } else {
            println("error - \(error)")
        }
    }

    println("Fetched data count is \(fetchedData.count)")
    completion(result: fetchedData.count > 0 ? fetchedData : nil)

}

我正在使用 AlamofireObjectMapper 通过 JSONFetch.jsonTest() 方法获取数据。现在的问题是如何从我的控制器中调用此 loadMoreData?

我在这里实现尾随闭包

loadMoreData(2){ (result) in

//after completion of your work this closure gets called
 println("your return \(result)")


}