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 trialmatt tripodi
2,673 PointsHelp with challenge
I can't figure out what I am doing wrong with this challenge
// We've already created a NSData object with some json encoded data for you
import Foundation
let jsonString : NSString = "{\"results\": \"success\"}"
let userCourseData : NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
let userCourseDictionary = NSDictionary = NSJSONSerialization.JSONObjectWithData(NSData, options: nil , error: nil) as NSDictionary
1 Answer
Greg Kaleka
39,021 PointsThere are two issues with your code. First, take a look at the color coding in your code (granted this wouldn't have helped you in the code challenge itself because of how code is colored there). You should see immediately where the last line of code doesn't match the prior two. Hint: you have two = symbols on the same line...
Second, you need to pass an actual NSData object to the method JSONObjectWithData()
. Instead you're passing it the type NSData. This is where you'll pass in the NSData object the challenge says it's created for you in that first comment.
Here's the solution:
// We've already created a NSData object with some json encoded data for you
import Foundation
let jsonString : NSString = "{\"results\": \"success\"}"
let userCourseData : NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
// Now you just need to decode it
let userCourseDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(userCourseData, options: nil , error: nil) as NSDictionary
matt tripodi
2,673 Pointsmatt tripodi
2,673 Pointsthank you, I didn't even notice I put two = signs