[英]'NSError' is not convertible to '@lvalue inout $T9' in Swift
so I'm trying to use a performRequestWithHandler block on a SLRequest object in my Swift iOS app and I can't deal with the NSError object. 所以我试图在我的Swift iOS应用程序中的SLRequest对象上使用performRequestWithHandler块,我无法处理NSError对象。 This is what how my code looks :
这就是我的代码的样子:
posts.performRequestWithHandler({(response:NSData!, urlResponse:NSHTTPURLResponse!, error:NSError!) in
self.data = NSJSONSerialization.JSONObjectWithData(response, options: NSJSONReadingOptions.MutableLeaves, error: &error)
})
And I have an error on the &error
that says : 'NSError' is not convertible to '@lvalue inout $T9' in Swift
. 我在
&error
错误上有一个错误: 'NSError' is not convertible to '@lvalue inout $T9' in Swift
。 Does anyone know what that means ? 有谁知道这意味着什么?
Thank you in advance. 先感谢您。
(I'm using Xcode Beta 6 v7 with OS X 10.10) (我正在使用Xcode Beta 6 v7和OS X 10.10)
You are reusing the error
variable passed in to the block - you simply have to define a local optional variable and pass its reference to JSONObjectWithData
您正在重用传入块的
error
变量 - 您只需定义一个本地可选变量并将其引用传递给JSONObjectWithData
var myError: NSError?
self.data = NSJSONSerialization.JSONObjectWithData(response, options:NSJSONReadingOptions.MutableLeaves, error: &myError)
That happens because JSONObjectWithData
needs a reference to a variable of NSError
type. 这是因为
JSONObjectWithData
需要引用NSError
类型的变量。 The one passed to the block is immutable - it points to an instance of NSError
, but cannot be reassigned to point to another instance, or set to nil in case of no error. 传递给块的那个是不可变的 - 它指向一个
NSError
实例,但不能重新分配指向另一个实例,或者在没有错误的情况下设置为nil。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.