Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Joey Bargo
31 PointsParse Swift Email Password Reset
Rather than using Alert PopUP, I was attempting to simply have a separate view controller to have email entry box with submit button to send reset email.
import UIKit
class ForgotPasswordViewController: UIViewController {
@IBOutlet weak var email: UITextField!
@IBAction func submitEmail(sender: AnyObject) {
PFUser.requestPasswordResetForEmailInBackground(email.text)
}
This code is "missing argument for parameter 'target' call", not sure how to implement this.
1 Answer
dungeonkeeperhf
3,272 PointsThe password reset uses a closure, This is an example from a previous project I was hired to make.
var initialEmail = emailInput.text
var email = initialEmail.lowercaseString
var finalEmail = email.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
PFUser.requestPasswordResetForEmailInBackground(finalEmail) { (success: Bool, error: NSError!) -> Void in
if (error == nil) {
var success = UIAlertController(title: "Success", message: "Success! Check your email!", preferredStyle: .Alert)
var okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
success.addAction(okButton)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(success, animated: false, completion: nil)
})
}else {
var errormessage = error.userInfo!["error"] as NSString
var error = UIAlertController(title: "Cannot complete request", message: errormessage, preferredStyle: .Alert)
var okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
error.addAction(okButton)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.presentViewController(error, animated: false, completion: nil)
})
}
}
}
Regina Soifer
7,386 PointsRegina Soifer
7,386 PointsI don't know if Parse updated this function recently but apparently your code doesn't work anymore.
The documentation doesn't mention the closure now and when trying to run your code I get a complaint about the arguments:
"Cannot invoke 'requestPasswordResetForEmailInBackground' with an argument list of type '(String ()-> Bool )'".