NSCocoaErrorDomain Code = 256 [英] NSCocoaErrorDomain Code=256

查看:2490
本文介绍了NSCocoaErrorDomain Code = 256的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been stuck with this for a while and don't seem to get around this.

我试图从网址中读取一个字符串作为URL的内容,但我得到一个奇怪的

I am trying to read the contents of an URL as a string from an URL, But i get a weird

错误 - >错误Domain = NSCocoaErrorDomain Code = 256无法完成操作(可可错误256.)

Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"

我的代码:

fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"www.example.com/iphone"] encoding:NSUTF8StringEncoding error:&error];                                     
    NSLog(@"%@",fetchedString);

    // if there is something wrong with the URL 
    if (error) {
        NSLog(@"Error -> %@", error);
        return ;
    }

我做错了什么?我试着使用获取作为NSData,但我回到null。

What am I doing wrong? I tried using getting as NSData as well, but I get null back.

推荐答案

是的,网址缺少方案:http://。

Yes, the URL is missing the scheme: "http://".

错误 - >错误域= NSCocoaErrorDomain Code = 256

"Error -> Error Domain=NSCocoaErrorDomain Code=256"

对于错误代码,请检查应用程式文件

For the error code check the Apple documentation:

可变错误域中的NSError代码。

NSError codes in the Cocoa error domain.

NSFileReadUnknownError = 256,

NSFileReadUnknownError

读取错误,原因未知

NSFileReadUnknownError
"Read error, reason unknown"

不是错误定义是非常有帮助的。 : - )

Not that the error definition is very helpful. :-)

也不要检查错误 nil 以确定是否存在错误,检查 nil 的返回值。 错误在成功执行后不能保证为 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 Code = 256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆