3

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) {
0

1 Answer 1

2

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)
     }          
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, just saw it! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.