如何在swift中使用MKLocalSearchCompletionHandler

时间:2015-12-13 09:06:00

标签: ios objective-c swift

MKLocalSearchCompletionHandler completionHandler = ^(MKLocalSearchResponse *response, NSError *error)
{ ... };

如何在swift中转换此完成处理程序?

2 个答案:

答案 0 :(得分:0)

以下是一些示例代码:

let localSearchRequest = MKLocalSearchRequest()
localSearchRequest.naturalLanguageQuery = "restaurants"

let localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.startWithCompletionHandler { (localSearchResponse, error) -> Void in
    print(localSearchResponse)
}

答案 1 :(得分:0)

以下是与Swift3兼容的示例代码:

let localSearchRequest = MKLocalSearchRequest()
localSearchRequest.naturalLanguageQuery = "restaurants"

let localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.start { (localSearchResponse, error) -> Void in
    print(localSearchResponse ?? "no results")
}