NSCocoaErrorDomain 256

I get the following error when trying to create a string from a file. Code below was added to viewDidLoad(). Test.txt file contains string "Hello, World!"


"From url path"

let path = NSBundle.mainBundle().pathForResource("Test", ofType: "txt")

let url = NSURL(string: path!)

do {

let string = try String(contentsOfURL: url!, encoding: NSUTF8StringEncoding)

print(string)

} catch {

}


However, this code works

"From string path"

let path = NSBundle.mainBundle().pathForResource("Test", ofType: "txt")

do {

let string = try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)

print(string)

} catch {

}


Am I missing something? This worked for me before. Now on Xcode 7/ iOS 9.0.2, I can't get it to work.


rey

Answered by developer007 in 74224022

Just found my issue. Should of NSURL(fileURLWithPath:).


Rey

Accepted Answer

Just found my issue. Should of NSURL(fileURLWithPath:).


Rey

NSCocoaErrorDomain 256
 
 
Q