Selecting only one location in the Location screen

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:

  1. 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: { $ == 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 ...

Get iOS 13 Programming for Beginners - Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.