ios - How to set UISearchBar in maps application in Swift? -


i new using swift , want make application uses maps , i'm trying include search bar(uisearchbar) when try make function makes search error in 1 line. here's code:

func performsearch(){     matchingitems.removeall()     let request = mklocalsearchrequest()     request.naturallanguagequery = searchtext.text     request.region = mapview.region      let search = mklocalsearch(request: request)     search.startwithcompletionhandler{          (response: mklocalsearchresponse!, error: nserror!) in          item in response.mapitems{              print("item name = \(item.name)")              print("latitude = \(item.placemark.location!.coordinate.latitude)")              print("longitude = \(item.placemark.location!.coordinate.longitude)")       }    } } 

i error in **startwithcompletionhandler** part says:

"cannot convert value of type '(mklocalsearchresponse!, nserror!) -> ()' expected argument type 'mklocalsearchcompletionhandler'".

can tell me how fix this?

if @ definition of mklocalsearchcompletionhandler, can see declaration not same :

typealias mklocalsearchcompletionhandler = (mklocalsearchresponse?, nserror?) -> void 

just replace code :

func performsearch(){     let request = mklocalsearchrequest()     request.naturallanguagequery = searchtext.text     request.region = mapview.region     let search = mklocalsearch(request: request)     search.startwithcompletionhandler{         (response: mklocalsearchresponse?, error: nserror?) in         if let items = response?.mapitems         {             item in items{                 print("item name = \(item.name)")                 print("latitude = \(item.placemark.location!.coordinate.latitude)")                 print("longitude = \(item.placemark.location!.coordinate.longitude)")             }         }     } } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -