Stuck on how to add a search bar and location to my Weather App

I need to add a search bar to my weather app so people can set to the location of their choice. Right now I have the ViewController set to let weatherURL = URL(string: “http://api.openweathermap.org/data/2.5/weather?q=Markham,CA?&units=metric&APPID=removed”)!

How does one alter this string?

Thank you

If someone types something in it’ll be saved in a variable, let’s say city

On your URL you’d use string interpolation

http://api.openweathermap.org/data/2.5/weather?q=\(city),CA?&units=metric&APPID=removed”)!

You’ll also notice the CA is hard coded so you will need to be able to search only city? Or add the state in the same way, or have some way to look up the state based on the city, and the put that into the url

Mike, thank you so much, now after I do that do I link to search box on my view Controller page? or do I need to link another page?

import MapKit

CLLocationManagerDelegate {

@IBOutlet weak var searchBar: UISearchBar!

@IBOutlet weak var cityLabel: UILabel!

and I get this error - Cannot find ‘city’ in scope

Yes! This is saying that my example variable of city is not defined anywhere. You need a new variable, called city.

“Cannot find in scope means you’re trying to use something that doesn’t exist.

I’d need to see more of your code, to get a better idea, but I would start with this tutorial Add Search Bar Quickly. The fast way to add a search bar into… | by Quang Quoc Tran | Medium