AFHTTPRequestOperation setCacheResponseBlock无法转换类型的值

时间:2015-10-22 14:28:27

标签: ios swift swift2 afhttprequestoperation xcode7.1

我正在快速使用AFHTTPRequestOperation

let operation : AFHTTPRequestOperation? = manager.GET(requestURL, parameters: nil,
            success: { (operation:AFHTTPRequestOperation!, responseObject:AnyObject!) -> Void in

...
...
...
                success(downloadedItems: responseObject)
            }, failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
                failure(responseFromCache: responseFromCache, error: error);
        })

我正在使用setCacheResponseBlock用于特定应用(ETag等)。

operation!.setCacheResponseBlock {(connection:NSURLConnection,cachedResponse:NSCachedURLResponse) - > NSCachedURLResponse in             打印("返回:200&#34)             responseFromCache = false             return cachedResponse         }

在将XCode更新为新版本XCode7.1之前,一切正常。

这是我的问题,我在更新后构建应用程序时收到此错误:

Cannot convert value of type '(NSURLConnection, NSCachedURLResponse) -> NSCachedURLResponse' to expected argument type '((NSURLConnection!, NSCachedURLResponse!) -> NSCachedURLResponse!)!'

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

检查错误信息后,我理解我的参数有问题。我在XCode中检查方法的声明,我理解刚刚更新的方法声明:

func setCacheResponseBlock(block: ((NSURLConnection!, NSCachedURLResponse!) -> NSCachedURLResponse!)!)

我更新了我的方法:

  operation!.setCacheResponseBlock { (connection: NSURLConnection!, cachedResponse: NSCachedURLResponse!) -> NSCachedURLResponse! in
            print("Returns:200")
            responseFromCache = false
            return cachedResponse
        }

和Xcode中构建成功消息的另一个快乐结局。希望这会对某人有所帮助。