'NSError' does not convert to '@lvalue inout $ T9' in Swift

so I am trying to use executeRequestWithHandler block on SLRequest object in my Swift iOS app and I cannot deal with NSError object. This is what my code looks like:

posts.performRequestWithHandler({(response:NSData!, urlResponse:NSHTTPURLResponse!, error:NSError!) in
    self.data = NSJSONSerialization.JSONObjectWithData(response, options: NSJSONReadingOptions.MutableLeaves, error: &error)
})

      

And I have a bug in &error

that says 'NSError' is not convertible to '@lvalue inout $T9' in Swift

. Does anyone know what this means?

Thanks in advance.

(I am using Xcode Beta 6 v7 with OS X 10.10)

+3


source to share


1 answer


You are reusing the variable error

passed to the block - you just need to define a local optional variable and pass its reference toJSONObjectWithData

var myError: NSError?
self.data = NSJSONSerialization.JSONObjectWithData(response, options:NSJSONReadingOptions.MutableLeaves, error: &myError)

      



This is because JSONObjectWithData

a reference to the type variable is required NSError

. The one passed to the block is unchanged - it points to an instance NSError

, but it cannot be reassigned to point to a different instance, or set to zero if there is no error.

+5


source







All Articles