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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -