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
Lyric Abbott
35,595 PointsConvert the JSON data to an NSDictionary
Let's assume we have a data object named userCourseData. We'll mock the data in this challenge, but it could easily have been returned from the Treehouse API with the code: let userCourseData = NSData(contentsOfURL: courseURL). Convert the JSON data to an NSDictionary and store it in a constant named userCourseDictionary. Hint: use the NSJSONSerialization class.
iM CONFUSED.....
3 Answers
Jacob McCaig
7,201 PointsI believe you're looking for something like this.
let userCourseDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(userCourseData, options: nil, error: nil) as NSDictionary
kaitlanlang
3,042 PointsI have got exactly what you have with exception of '!' after userCourseData and it fails, this is the technique that worked in Xcode . Its seems in my novice opinion that they have also thrown in an optional as an after thought in the pre populated question code. Loosing faith in this course to keep up with changes in Xcode. Its leaving us mighty confused whether we are learning it right first time. I could be wrong though. Is the parser up to date in parsing changes in Xcode?!!!!!!
below is what the parser gives with optional like used in Xcode and parsed in Xcode
swift_lint.swift:10:96: error: operand of postfix '!' should have optional type; type is 'NSData' let userCourseDictionary : NSDictionary = NSJSONSerialization.JSONObjectWithData(userCourseData!, options: nil, error: nil) as NSDictionary
Now my answer to question worked when I removed optional after userCourseData. I am still not happy as I need clarification why similar example required optional in Xcode ( which wasn't cleared up in video). I have a big fat question mark was I and Xcode right or are you and your parser right or are you yet to catch up. If you guys aren't up to date i really need a months free of fees so I can twiddle my thumbs and wait until you catch up and I can guarantee what i am dealing with is accurate and up to date. No offence is intended, i need learning materials to be correct. Its hard enough learning new concepts without interference of errors.
Now the above could be the ravings of a frustrated learner and her assumptions could be wrong, but i second the sentiments of the original question asker "I'm confused" the clarity from my persective in questioning in general is poor. You only work out what is being asked by mirroring something from video and tweaking or the forum. I have generalised but it is frequent. You should not need to go to a forum to understand a question, you should go there if your stuck on the answer to gain knowledge to get answer. Email me if you need as it probably best I don't express course frustrations openly any more.
To have faith in what I am doing need to know when you have checked all your source material for currency with Xcode issues completely and noted correct as of date xx/xx/xxxx
I seem like a pain in the butt I'm ready to walk away from a good course through lack of course primacy.
mark lesbirel
2,012 PointsHmmmm. I am much more of a novice and I too have noticed issues with the code we are told works in the videos from the code that actually works.
Generously, I think it's fun to try and work out what has changed - but that's only because I have so far managed to (with help from here too).
I guess I might not be so forgiving if I come across something I cannot find the solution to...