Combining search result table with Maps

I’m trying to combine the Store Search table (search results) (Book 4) with a map view (my locations book 3). The longitude and latitude are part of the array downloaded from the website.

I can’t work out how to pass the array created from the search to the map view controller as I don’t want to pass the long and lats from the table row but for all of the results from the search.

I’ve been using the MapKit tutorial (18 March 2015) and could query the database again, but think there must be a way to pass the array between the Search View Controller and the Map View Controller.

Be really grateful for any help with this,

Thanks,
Claire

Usually this is done by giving the Map View Controller a property for it. When the Search View Controller segues to the Map View Controller, you assign the array that holds the search results to that property. Then the Map View Controller can read from its own copy of that array.

This is helpful for me at some points. thanks …


Virtuoso

Thanks for coming back to me.

What would the code be for the array in the segue? Everything I try, xCode doesn’t like :frowning:

The array is the searchResult array generated in the Search.swift file as per the Store Search book 4 project.

Thanks for your help, really appreciate it,

Claire

In prepareForSegue, you simply do something like:

controller.searchResults = searchResults

This is something you’ve done several times before in the Checklists and MyLocations tutorials, so have a look there to remind yourself how it’s done. :wink:

Thanks so much. I just seem to have a mental block when it comes to arrays and the difference between searchResult and searchResults. Your tutorials are fantastic btw, thank you

Do you know how to proceed now or are you still stuck?

I’m still stuck to be honest, but I haven’t had a chance to go back over the Locations project yet.

Thanks for all your help,

Claire

Oh my life, it was incredibly easy (once I had my longitude and latitude the right way round).

Think I may be getting the hang of arrays and dictionaries, thanks again for your help.

Great to hear you figured it out! This probably won’t be the last time where you spend hours looking at something that doesn’t work only to realize it was something simple. But as you get more experience, you’ll get better at figuring this stuff out. :slight_smile: