NSCocoaErrorDomain 代码=256

编程入门 行业动态 更新时间:2024-10-23 23:19:51
本文介绍了NSCocoaErrorDomain 代码=256的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经坚持了一段时间,似乎没有解决这个问题.

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

本文发布于:2023-11-26 16:58:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634445.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   NSCocoaErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!