Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:无法转换类型“NSData!”键入“NSURLRequest!”_Swift_Nsurlrequest - Fatal编程技术网

Swift:无法转换类型“NSData!”键入“NSURLRequest!”

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

我在Swift中又遇到了一个奇怪的错误

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错误仍然是垃圾:谢谢!快速的错误有时很奇怪。是的,快速的错误仍然是垃圾:谢谢!快速的错误有时很奇怪。