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

Error: Expected member name or constructor call after you type name.

I get this error: "Expected member name or constructor call after you type name." when I put the code in from the teacher's notes: NSString(contentsOfURL: NSURL, encoding: UInt, error: NSErrorPointer). I did what Xcode recommended me to do but it doesn't return what it's supposed to.

Pasan Premaratne Chris Upjohn Adam Moore Christian Andersson

Any help would be appreciated! Thanks!

2 Answers

Jared Watkins
Jared Watkins
10,756 Points

Rolando,

Are you trying to print the JSON contents to the console?

NSString(contentsOfURL: NSURL, encoding: UInt, error: NSErrorPointer) is the formatting guideline. It's not functioning code. For NSURL, you need something that is an actual URL. For the encoding, you need to specify the type of encoding to expect. Same goes for the error.

So, if you're going to print the JSON data to the console like Pasan does in the video, you would put something like this:

// See the JSON data in the console
var urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println(urlContents)

location is a variable storing the contents of the JSON weather URL.

I'm sure someone can more eloquently explain this.

Thank you!