我已经坚持了一段时间,似乎没有解决这个问题.
I have been stuck with this for a while and don't seem to get around this.
我正在尝试将 URL 的内容作为 URL 中的字符串读取,但我得到一个奇怪的
I am trying to read the contents of an URL as a string from an URL, But i get a weird
Error -> Error Domain=NSCocoaErrorDomain Code=256 操作无法完成.(Cocoa 错误 256.)"
Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
我的代码:
fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.example/iphone"] encoding:NSUTF8StringEncoding error:&error]; NSLog(@"%@",fetchedString); // if there is something wrong with the URL if (error) { NSLog(@"Error -> %@", error); return ; }我做错了什么?我也尝试使用作为 NSData 获取,但我得到了空值.
What am I doing wrong? I tried using getting as NSData as well, but I get null back.
推荐答案是的,URL 缺少方案:".
Yes, the URL is missing the scheme: "".
错误 -> 错误域=NSCocoaErrorDomain 代码=256"
"Error -> Error Domain=NSCocoaErrorDomain Code=256"
对于错误代码,请检查 Apple 文档:
For the error code check the Apple documentation:
Cocoa 错误域中的 NSError 代码.
NSError codes in the Cocoa error domain.
NSFileReadUnknownError = 256,NSFileReadUnknownError读取错误,原因未知"
NSFileReadUnknownError "Read error, reason unknown"
并不是说错误定义很有帮助.:-)
Not that the error definition is very helpful. :-)
也不要检查error是否为nil来判断是否有错误,检查nil的返回值.error 不保证成功执行时nil.
Also do not check if error is nil to determine if there is an error, check the return value for nil. error is not guaranteed to be nil on successful execution.
更多推荐
NSCocoaErrorDomain 代码=256
发布评论