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 Making a Network Call

NSData dataWithContentsOfURL Deprecated for Swift?

I tried searching through the documentation as well as a couple of previously asked questions here on Treehouse but i can't seem to find a solution to this issue. NSData.dataWithContentsOfURL is not working in the current version of Xcode on Yosemite. The code:

let weatherData = NSData.dataWithContentsOfURL(forecastURL, options: nil, error: nil)

Throws the error " 'NSString is not a subtype of 'NSURL' ".

A previous discussion surrounding this video suggested using this method instead, yet this also is no longer working:

NSData(contentsOfURL: forecastURL!)

Using the bang (!) operator gives an error of "Operand of postfix '!' should have optional type; type is 'String' " and not using the bang operator gives the error "Extra argument 'contentsOfURL' in call".

I also tried using the additional suggested arguments for contentsOfURL ("options: nil, error: nil") which also is not working.

I'm not sure how to proceed and would love some assistance.

4 Answers

I just posted some code that compiles correctly under the Questions section of this video. Given that Swift has changed quite a bit, the code in the video will not work until it gets updated by the Treehouse team. My code compiles and at least will let you move forward with the course until they get a chance to rework the material. Hope it helps!

I can't find the solution, do you've the code?

Angelo Paulo Lapus
Angelo Paulo Lapus
2,614 Points

Any updates on this thread? I'm also having a problem calling the NSData.dataWithContentsOfURL since it's not showing on my IDE.

If you check out the video from the course it looks like they've added some teacher's notes about the issue.

We all have the problems

got stuck on this code to over here

anyone get update ?