Reputation: 43
NSURL *url = [NSURL URLWithString:@"http://iminichrispy.com/Xcode/TextFromWeb.txt"];
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSStringEncodingConversionAllowLossy error:nil];
label.text = content;
I have tried the following
var url:NSURL = NSURL(string: "http://iminichrispy.com/Xcode/TextFromWeb.txt")
var content:NSString = NSString(contentsOfURL: url, encoding: NSStringEncodingDetectionAllowLossyKey, error: nil)
label.text = content
At nil I keep getting the error: "Extra argument 'error' in call"
Upvotes: 2
Views: 909
Reputation: 122419
The encoding
parameter is supposed to be an encoding (which is an integer), not conversion option (which is a string, so the types don't match):
var url:NSURL? = NSURL(string: "http://iminichrispy.com/Xcode/TextFromWeb.txt")
var content:NSString? = NSString(contentsOfURL: url!,
encoding: NSUTF8StringEncoding,
error: nil)
Upvotes: 3
Reputation: 3628
Use something like this:
var e : NSError?
let content : NSString = NSString(contentsOfURL:url, encoding:NSUTF8StringEncoding, error:&e)
nil value is not supposed to be there.
Upvotes: 0