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

var urlContents = NSString **stringWithContentsOfUrl** doesn't exist

how come i can't select NSString.stringWithContentsOfUrl in my Xcode? I'm running Xcode 6.1. This is in conjunction with the "Using Our JSON Data" section.. Thanks!

1 Answer

Hi Gary,

As of OS X 10.4 the Cocoa Foundation framework set this method as deprecated when passing just an NSURL instance which is why you can select it, instead you now need to use the same method but with an encoding type and error closure which you can get more information about here.

Hope that helps.

Hi Chris,

Thanks for the reply. My problem is I can't select the stringWithContentsOfUrl:* it doesn't appear in the list of methods in the drop down for NSString.. So when I type NSString. i can't see the method I want (stringWithContentsOfUrl: blah).

Am I missing some classes or libraries with my Xcode build?

Thanks

Gary

Hi Gary,

It appears by the code you wrote above they you're using Swift which uses a modified version of the Cocoa Foundation framework, see the below for an example of using this method within Swift.

var e: NSError?
let url: NSURL = NSURL(string: "http://www.google.com")
let string = NSString(contentsOfURL: url, encoding: NSUTF8StringEncoding, error: &e)

Many thanks Chris, this has really helped me out.

I'm getting confused when to use . notation or parenthesis.. I may need to revisit some of the lessons.

Gary