XCode 7 beta 6 (Swift 2) initializing error

I am currently having problems declaring a String. I wa previously able to use this in XCode 6 but now I can't.


The command is:

let HTMLString = NSString(contentsOfURL: myURL, encoding: NSUTF8StringEncoding, error: &error)


But I am getting the error:


Cannot invoke initializer for type 'NSString' with an argument list of type '(contentsOfURL: NSURL, encoding: UInt, error: inout NSError?)'


Any ideas?


Thanks

Answered by Tia Lapis in 48122022

Yes, read on the new error handling in Swift2.


do {
  try file = NSString(contentsOfFile: "test.txt", encoding: NSUTF8StringEncoding)
} catch let error as NSError {
  print(error.localizedDescription)
}
Accepted Answer

Yes, read on the new error handling in Swift2.


do {
  try file = NSString(contentsOfFile: "test.txt", encoding: NSUTF8StringEncoding)
} catch let error as NSError {
  print(error.localizedDescription)
}
XCode 7 beta 6 (Swift 2) initializing error
 
 
Q