Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Network Programming with Swift 2 Fetching Data From the Web Constructing a URL

Danny Kilkenny
Danny Kilkenny
4,507 Points

Having trouble with an error in the code of Constructing a URL video

I have an error that keeps popping up that says "Cannot cover value of type 'NSURL?' to expected argument type 'URL?' "

Can anyone help explain why this error keeps popping up? I am using swift 3.0 FYI

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let icon = WeatherIcon.PartlyCloudyDay.image
        let currentWeather = CurrentWeather(temperature: 56.0, humidity: 1.0, precipitationProbability: 1.0, summary: "Wet and Rainy", icon: icon)

        display(weather: currentWeather)

        let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(forecastAPIKey)")
        let forecastURL = NSURL(string: "37.8267,-122.423", relativeTo: baseURL)


    }

1 Answer

Danny Kilkenny
Danny Kilkenny
4,507 Points

I actually figured out the solution to the problem. Here is the code if anyone has this problem in the future:

let baseURL = URL(string: "https://api.forecast.io/forecast/\(forecastAPIKey)/")
        let forecastURL = URL(string: "37.8267,-122.423", relativeTo: baseURL!)