【发布时间】:2016-02-16 15:30:22
【问题描述】:
我在 Xcode 中有以下代码:
NSError *error = [[NSError alloc] init];
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
它会在日志中引发以下错误
[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This message shown only once.
也许,你会告诉我答案在日志中,但我不明白如何初始化 NSError。
【问题讨论】:
-
因为 sendSynchronousRequest 会自己分配错误。这就是为什么你只给出一个指向错误(*)的指针。所以你创建的 Instanz 将永远不会被使用并且是无效的。