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) Concurrency Using Our JSON Data

Cihan özener
Cihan özener
1,807 Points

I cant get stringWithContentsOfURL with NSString what can I do to fix it?

İn the tutorial Pasan writes NSString. and stringwithcontents of URL show up, I can't get it on my xcode

5 Answers

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: {(location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in

var urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil) println( urlContents) })

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

It seems that the Xcode Documentation API reference does not always show code that is deprecated (No longer used). I have found that using the online resource

https://developer.apple.com/library/ios/navigation/

is more current and up to date.

Jason Wayne
Jason Wayne
11,688 Points

Could you please show how you have written your code?

Try checking if you have the stringWithContentsOfURL in square brackets. For instance, in Objective-C, [NSString stringWithContentsOfURL:]. Since it is a class method, method has to be in brackets.

In Swift, you probably would do something like, theString(stringWithContentsOfURL..........)

But it's kind of hard to tell without seeing the code.

There's also a possibility that it might be an Xcode bug. I have faced instances where, my code doesn't autocomplete for anything.

the quiz should be updated as well.....

Jason Wayne
Jason Wayne
11,688 Points

Usually when I wanna look up something, I'll just search the web for Apple's Doc. I rarely use Xcode Doc.