【问题标题】:Incompatible pointer types assigning to 'NSHTTPURLResponse *' from 'NSURLResponse *'从“NSURLResponse *”分配给“NSHTTPURLResponse *”的不兼容指针类型
【发布时间】:2011-08-09 23:04:32
【问题描述】:

在下面的代码中,我收到了从“NSURLResponse *”分配给“NSHTTPURLResponse *”的警告不兼容的指针类型。此方法是 Sharekit 的一部分。

带有警告的行是粗体/斜体:

    - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)aResponse
{
    if (response)
        [response release];
    ***response = [aResponse retain];***
    [responseData setLength:0];
}

请有人帮忙!

谢谢!

【问题讨论】:

    标签: ios warnings sharekit incompatibility


    【解决方案1】:

    对于编译器,aResponse[aResponse retain] 的结果是一个 NSURLResponse。但是我猜response 是一个 NSHTTPURLResponse。由于 NSURLResponse 是 NSHTTPURLResponse 的超类,你不能直接赋值——但你可以使用强制转换来移除警告:

    response = (NSHTTPURLResponse *)[aResponse retain];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-29
      • 2018-11-17
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多