简体   繁体   中英

Parse Swift Update Errors

After the recent Swift update, I have been trying to debut a few lines of code and don't seem to be understanding what's wrong..

The lines are

 PFGeoPoint.geoPointForCurrentLocationInBackground {

with the error message "Cannot invoke 'geoPointForCurrentLocationInBackground' with an argument list of type '((PFGeoPoint", NSError!) -> Void)'"

The second line is

 PFUser.logInWithUsernameInBackground(username:usernameTextField.text, password:passwordTextField.text, target: self) {

With the error "Extra argument 'target' in call"

I've tried looking online and debugging these, but I honestly have no idea what's going on. It seems to be an error in the parse code and I'm not sure why that is...

Edit: I fixed second error I was having. code:

PFUser.logInWithUsernameInBackground(usernameTextField.text, password:passwordTextField.text) {

Start from Swift 1.2, the Failable Casts is introduced. you can use the PFGeoPoint.geoPointForCurrentLocationInBackground method like the following:

If you're quite sure that the downcasting will succeed, you can use as! to force the cast:

PFGeoPoint.geoPointForCurrentLocationInBackground {
    (point:PFGeoPoint!, error:NSError!) -> Void in   
    if (error == nil) {
        println(point)
     } else {
        println(error)
     }             
}

If you're not sure if the casting will succeed, just use the as? operator. By using as? , it returns an optional value, but in case the downcasting fails, the value will be nil.

PFGeoPoint.geoPointForCurrentLocationInBackground {
    (point:PFGeoPoint?, error:NSError!) -> Void in  
     if (error == nil) {
        if let myPoint = point {
           println(myPoint)
        }
     } else {
        println(error)
     }          
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM