简体   繁体   English

在Swift中,'NSError'不能转换为'@lvalue inout $ T9'

[英]'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.

相关问题 Swift:Int不能转换为'@lvalue inout _' - Swift: Int is not convertible to '@lvalue inout _' 在Swift 3中inout字符串不可转换为String - inout String is not convertible to String in Swift 3 Swift错误:'((AFHTTPRequestOperation!,NSError?)->不能转换为'((AFHTTPRequestOperation?,NSError)->无效? - Swift error : '(AFHTTPRequestOperation! , NSError? ) -> is not convertible to '((AFHTTPRequestOperation? , NSError) -> Void? 'ErrorType'无法转换为'NSError' - 'ErrorType' is not convertible to 'NSError' “ NSError”不可转换为“ UInt8” - 'NSError' is not convertible to 'UInt8' Swift 2 - CoreData - NSManagedObjectContext无法使用类型'(inout NSError?)'的参数列表调用'save' - Swift 2 - CoreData - NSManagedObjectContext Cannot invoke 'save' with an argument list of type '(inout NSError?)' 错误:“ inout IndexPath”无法转换为“ IndexPath” - Error:'inout IndexPath' is not convertible to 'IndexPath' SwiftyJSON-'inout JSON'不能转换为'JSON' - SwiftyJSON - 'inout JSON' is not convertible to 'JSON' Swift [String:AnyObject]无法转换为T Swift数组 - Swift[String: AnyObject] not convertible to T Swift Arrays 使用Swift中的Generics,'Object'不能转换为'T' - 'Object' is not convertible to 'T' using Generics in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM