gpt4 book ai didi

objective-c - 获取 &error 没有错误

转载 作者:行者123 更新时间:2023-11-28 18:43:21 25 4
gpt4 key购买 nike

出于某种原因,当我执行 NSURLConnection 时没有错误存在,但我收到错误。

NSLog(@"Sending string to server. ID:11118");
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"Response from server received. ID:11119");
NSString *responseString = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

if (&error)
{
//Handle Error
NSLog(@"Error getting a server response! (scm) Error %i: %@", [error code], [error localizedDescription]);
UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"Error getting a server response!" message:[NSString stringWithFormat:@"Error %i: %@", [error code], [error localizedDescription]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[theAlert show];
}

[error code] 显示 0[error localizedDescription] 显示 Null >.

有什么想法吗?

最佳答案

不要检查 NSError 对象来确定是否发生了错误。按照惯例,您应该检查产生错误的方法的返回值。如果结果为 nilNO,那么您才应该继续检查错误。此外,您不是在检查错误对象,而是在检查错误对象内存中地址的有效性。

在您的情况下,仅当 urlDatanil 时才继续检查错误。

关于objective-c - 获取 &error 没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8438253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com