私は何かが間違っているに違いない - コードを次のように変更しましたが、まだエラーが発生しています。私は明らかに何かを誤解しています。助けに感謝します。Swift3での位置検索のための補完ハンドラ
func performSearch() {
mapView.delegate = self
matchingItems.removeAll()
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = searchText.text
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start(completionHandler: ({(response: MKLocalSearchResponse?,error: NSError?) in
if error != nil {
return
}
if response!.mapItems.count == 0 {
self.resultOfSearch.text = ("No matches found")
}else{
self.found = response!.mapItems
if let items = response?.mapItems, items.count > 0 {
while self.n < 3 && self.n < response!.mapItems.count { self.locationsRet[(response!.mapItems[self.n].name!)] = self.n; self.n = self.n + 1}
self.n = 0
}else{
self.alert2("NOLOC")
}
self.alert3(self.locationsRet, found: self.found)
}
} as? MKLocalSearchCompletionHandler)!)
}
でも、私は間違っていますか?
このコードはスウィフト2でうまくいきましたが、クラッシュスウィフト3.
func performSearch() {
mapView.delegate = self
matchingItems.removeAll()
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = searchText.text
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start(completionHandler: ({(response: MKLocalSearchResponse?,error: NSError?) in
if error != nil {
//self.resultOfSearch.text = ("Error occured in search:\(error!.localizedDescription)")
} else if response!.mapItems.count == 0 {
self.resultOfSearch.text = ("No matches found")
// }else if response!.mapItems.count > 1 {
}else{
self.found = response!.mapItems
for _ in response!.mapItems {
if response!.mapItems.count > 0 {
while self.n < 3 && self.n < response!.mapItems.count { self.locationsRet[(response!.mapItems[self.n].name!)] = self.n; self.n = self.n + 1}
self.n = 0
}else{
self.alert2("NOLOC")
}
}
self.alert3(self.locationsRet, found: self.found)
}
} as? MKLocalSearchCompletionHandler)!)
}
このコードは、今、このエラーを与える
。あなたがこの方法のようMKLocalSearch
にstartメソッドを呼び出す必要があるので、
function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) ->() to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) ->()]> of generic specialization <preserving fragile attribute,()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
-> 0x5bf2e0 <+124>: trap
を働いていましたか? MKLocalSearchCompletionHandler)!) - 私は今理解してありがとう – Jeremy
ようこそmate :) –