Post

Replies

Boosts

Views

Activity

Reply to How can I format a space that is entered into textfield and code the space into a URL?
Thanks for the replies, I had to no idea URLComponents was a thing. I've reformatted the code to look like this: import UIKit import CoreLocation protocol APIManagerDelegate {   func didUpdateData(_ APIManager: APIManager, data: APIManager)   func didFailWithError(error: Error) } struct APIManager {      let dataURL = "https://api.openweathermap.org/data/2.5/weather?"   let appId = "appid="   let myApiKey = "..."   var delegate = APIManagerDelegate?.self   func fetchData(location: String) {     var urlComponents = URLComponents(string: dataURL)     urlComponents?.queryItems = [       URLQueryItem(name: "appId", value: appId),       URLQueryItem(name: "units", value: "imperial"),       URLQueryItem(name: "q", value: location),     ]     performRequest(url: urlComponents?.url)   }       func performRequest(url: URL?) {     if let url = url {       let session = URLSession(configuration: .default)       let task = session.dataTask(with: url) { (data, response, error) in         if error != nil {           print(error!)           return         }         if let safeData = data {           self.parseJSON(cityData: safeData)         }       }       task.resume()     }   }           func parseJSON(cityData: Data) {     let decoder = JSONDecoder()     do {       let decodedData = try decoder.decode(APIResults.self, from: cityData)       print(decodedData.name)       print(decodedData.main.temp)       print(decodedData.coord.lat)       print(decodedData.coord.lon)     } catch {       print(error)     }   } } however nothing is printing in the debug console, so I'm thinking there may still be a problem w/how the URL is being formatted. Is there something I'm missing/ not understanding?
May ’21
Reply to Need help w/escaping closures for API call
Thanks, your comments helped out a lot. I think the main issue I was concerned with was whether or not I was using the right info in the completion handlers. It currently runs and doesn't throw any errors. Next time I post a question I'll be sure to include more info, and thanks for the tip on line 47. I'll try that and see if anything changes.
May ’21