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 NSString error in Swift

I get error in Swift course Build A Weather App - the bit where I am retrieving the data from the URL location.

What the course says to use:-

var urlContents = NSString.stringWithContentsOfURL
(location, encoding: NSUTF8StringEncoding, error: nil)

gets 2 errors;-

'Could not find an overload for "stringWithContentsOfURL" that accepts the supplied arguments

"Cannot convert the expressions type '(NSURL)', encoding: UInt, error: NilLiteralConvertible)' to type 'NilLiteralConvertible'

tried this;

var urlContents = NSString(location, encoding: NSUTF8StringEncoding, error: NilLiteralConvertible.self)

gets build failed.

Any help please?

1 Answer

THis seemed to do it...

var urlContents = String(contentsOfURL: forecastURL!, encoding: NSUTF8StringEncoding, error: nil)

Yay!