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 Build a Weather App with Swift (Retired) Pulling Data From the Web JavaScript Object Notation

Why is my API not working with these ?

import UIKit import Foundation

let apiKey = "api key"
let locationPoints = "6.496944, 3.382426"

let baseURL = "https://api.forecast.io/forecast/\(apiKey)"
let encodedPoints =    locationPoints.stringByAddingPercentEscapesUsingEncoding(N SUTF8StringEncoding)! 

let forecastURL = NSURL(string: "\(baseURL)/\(encodedPoints)")!
let weatherAPI = NSData(contentsOfURL: forecastURL, options: nil, error: nil)
println(weatherAPI)

2 Answers

Frank Shi
Frank Shi
1,859 Points

Hi Ayoola, I just tested your code using playground and it works without problems. What is the detail error you found?

Ben Griffith
Ben Griffith
5,808 Points

There appears to be a space in your NSUTF8StringEncoding

locationPoints.stringByAddingPercentEscapesUsingEncoding(N SUTF8StringEncoding)