Parse Swift update errors
After a recent Swift update, I've been trying to debut a few lines of code and don't seem to understand what's wrong.
Lines
PFGeoPoint.geoPointForCurrentLocationInBackground {
with the error message "Unable to call" geoPointForCurrentLocationInBackground "with an argument list like" ((PFGeoPoint ", NSError!) → Void) '"
Second line
PFUser.logInWithUsernameInBackground(username:usernameTextField.text, password:passwordTextField.text, target: self) {
With the error "Additional argument" target "in the call
I've tried searching online and debugging them, but I honestly have no idea what's going on. It seems to be a bug in the syntax code and I'm not sure why this is ...
Edit: I fixed the second error I had. code:
PFUser.logInWithUsernameInBackground(usernameTextField.text, password:passwordTextField.text) {
source to share
Start with Swift 1.2, add Failable Casts . you can use the method PFGeoPoint.geoPointForCurrentLocationInBackground
like this:
If you are confident that understating success will be successful, you can use as!
to enforce:
PFGeoPoint.geoPointForCurrentLocationInBackground {
(point:PFGeoPoint!, error:NSError!) -> Void in
if (error == nil) {
println(point)
} else {
println(error)
}
}
If you are not sure if the casting will be successful, just use the operator as?
. By using as?
, it returns an optional value, but if 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)
}
}
source to share