stringWithContentsOfURL generating compile error
Can someone tell me why:
NSString *content = [NSString stringWithContentsOfURL:theURL encoding:NSASCIIStringEncoding];
is generating compile error:
warning: 'NSString' may not respond to '+stringWithContentsOfURL:encoding:'
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
theURL is of type NSURL, and without the encoding bit, it works....kind of. Returns garbage, which I assume is due to incorrect encoding.
Thanks a bunch,
Todd
I think you've omitted the error: argument in the signature of the API.
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/clm/NSString/stringWithContentsOfURL:encoding:error:stringWithContentsOfURL:encoding:error:
Returns a string created by reading data from a given URL interpreted using a given encoding.
+ (id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error
Parameters
- url
The URL to read.
- enc
The encoding of the data at url.
- error
If an error occurs, upon returns contains an
NSErrorobject that describes the problem. If you are not interested in possible errors, you may pass inNULL.
Return Value
A string created by reading data from URL using the encoding, enc. If the URL can’t be opened or there is an encoding error, returns nil.
Availability
- Available in Mac OS X v10.4 and later.
See Also
Whoo! What a simple mistake. Sometimes the answer is right there in front of you, I read through the docs and would have sworn I had it right.
Thank you very much,
Todd