You want the user to only select one location, and if another is selected, the location selected earlier should be deselected. Let's modify LocationDataManager to do this now. Perform the following steps:
- Click LocationDataManager.swift. Implement this method before the closing curly brace:
func findLocation (by name: String) -> (isFound:Bool, position:Int) { guard let index = locations.firstIndex ( where: { $0.city == name} ) else { return (isFound:false, position:0) } return (isFound: true, position: index)}
This method takes a city name as a parameter. It then searches the locations array for a matching city, and if found, returns true and the index where that array item is stored ...