Search code examples
iosswiftparse-platform

PFQuery - How to get NSError?


Parse API for get and find methods have signature returning object(s) and NSError but signature that i see in XCode returns Error and not NSError. Pls see some examples.

 let userQuery = PFUser.query()
    userQuery?.getObjectInBackground(withId: <#T##String#>, block: { (<#PFObject?#>, <#Error?#>) in
        <#code#>
    })

PFUser.current()?.fetchInBackground(block: { (<#PFObject?#>, <#Error?#>) in
            <#code#>
        })

PFQuery().findObjectsInBackground { (<#[PFObject]?#>, <#Error?#>) in
            <#code#>
        }

Due to this i am able to find out the error code.

Why so? i am using Parse iOS SDK 1.15.4.

Thanks

Ashish


Solution

  • NSError conforms to the Error protocol so just bridge cast the type

    let nsError = error as NSError
    let errorCode = nsError.code