Swift:无法转换类型“NSData!”键入“NSURLRequest!”
我在Swift中又遇到了一个奇怪的错误Swift:无法转换类型“NSData!”键入“NSURLRequest!”,swift,nsurlrequest,Swift,Nsurlrequest,我在Swift中又遇到了一个奇怪的错误 Cannot convert the expression's type 'NSData!' to type 'NSURLRequest!' 我的代码是: var request = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 5) var response : NSURLRespon
Cannot convert the expression's type 'NSData!' to type 'NSURLRequest!'
我的代码是:
var request = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 5)
var response : NSURLResponse?
var error : NSError?
NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error: error)
//The error is reported at the above line
这是什么意思?我尝试将NSData转换为NSURLRequest。我不确定为什么会显示这样的消息,但您缺少&for inout参数
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
我不知道为什么会显示这样的消息,但您缺少&for-inout参数
NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)
您确定没有定义两次请求吗?例如,一次作为属性,第二次作为局部变量?@Sulthan No,我肯定没有。顺便说一句,在Swift中,您可以将cachePolicy:NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData替换为cachePolicy:.ReloadIgnoringLocalCacheData。请参阅Swift手册的枚举部分。您确定没有两次定义请求吗?例如,一次作为属性,第二次作为局部变量?@Sulthan No,我肯定没有。顺便说一句,在Swift中,您可以将cachePolicy:NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData替换为cachePolicy:.ReloadIgnoringLocalCacheData。请参阅Swift书籍的枚举部分。是的,Swift错误仍然是垃圾:谢谢!快速的错误有时很奇怪。是的,快速的错误仍然是垃圾:谢谢!快速的错误有时很奇怪。