如何在Xcode中使用parse和swift设置登录页面(“SigninBackgroundithBlock”错误)?
我正试图在Xcode中使用parse和swift设置登录页面,但我一直在“SigninBackgroundithBlock”中遇到一个错误,我如何才能做到这一点? 我一直收到消息 无法使用参数列表调用“SignupInBackgroundithBlock” 输入Bool!,N错误!->空虚 到目前为止,这就是我所拥有的,我只是有一个错误的那部分如何在Xcode中使用parse和swift设置登录页面(“SigninBackgroundithBlock”错误)?,xcode,swift,parse-platform,Xcode,Swift,Parse Platform,我正试图在Xcode中使用parse和swift设置登录页面,但我一直在“SigninBackgroundithBlock”中遇到一个错误,我如何才能做到这一点? 我一直收到消息 无法使用参数列表调用“SignupInBackgroundithBlock” 输入Bool!,N错误!->空虚 到目前为止,这就是我所拥有的,我只是有一个错误的那部分 import UIKit import Parse class EmailLogin: UIViewController, UITextFieldD
import UIKit
import Parse
class EmailLogin: UIViewController, UITextFieldDelegate {
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var statusLabel: UILabel!
@IBOutlet weak var createAccountButton: UIButton!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
emailTextField.delegate = self;
passwordTextField.delegate = self;
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func createAccountButtonPressed(sender: AnyObject)
{
if verifyEmailDomain(self.emailTextField.text)
{
createAccount(self.emailTextField.text, password: self.passwordTextField.text)
}
else
{
//self.statusLabel.text = "Email domain is not valid.";
let alert = UIAlertView()
alert.title = "Invalid Email Domain"
alert.message = "Make sure you entered in your address correctly. If you did, ask your system about using PageMD! Thanks."
alert.addButtonWithTitle("Close")
alert.show()
}
}
func verifyEmailDomain(email: String) -> Bool
{
var isVerifiedDomain = false
let userDomain: String = (email.componentsSeparatedByString("@")).last!
//NSLog(userDomain)
let validDomainsFileLocation = NSBundle.mainBundle().pathForResource("ValidDomains", ofType: "txt")
var validDomainsFileContent = NSString(contentsOfFile: validDomainsFileLocation!, encoding: NSUTF8StringEncoding, error: nil)
//NSLog(validDomainsFileContent!)
let validDomains = validDomainsFileContent!.componentsSeparatedByString("\n")
for domain in validDomains
{
NSLog(domain as! NSString as String)
if userDomain == (domain as! NSString)
{
isVerifiedDomain = true
break
}
}
return isVerifiedDomain
}
func createAccount(email: String, password: String)
{
var newUser = PFUser()
newUser.username = email // We want the user to login only with their email.
newUser.email = email
newUser.password = password
//this where i get my error//
newUser.signUpInBackgroundWithBlock { (succeeded: Bool!, error: NSError!) -> Void in
if error == nil
{
// Account created successfully!
if succeeded == true
{
self.statusLabel.text = "Account created!"
}
}
else
{
if let errorField = error.userInfo
{
self.statusLabel.text = (errorField["error"] as NSString)
}
else
{
// No userInfo dictionary present
// Help from http://stackoverflow.com/questions/25381338/nsobject-anyobject-does-not-have-a-member-named-subscript-error-in-xcode
}
}
}
}
func textFieldShouldReturn(textField: UITextField) -> Bool
{
textField.resignFirstResponder()
return true;
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
如果您使用的是swift 1.2 Xcode 6.3,则需要通过以下方式调用该函数:
newUser.signUpInBackgroundWithBlock({(succeeded:Bool, error:NSError?) -> Void in
})
如果您使用的是swift 1.1 Xcode 6.1、6.2,则需要通过以下方式调用该函数:
newUser.signUpInBackgroundWithBlock({(succeded:Bool, error:NSError!) -> Void in
})
这是不同的,因为swift更新1.2在使用选项时发生了变化
另一种方法是这样写:
在新旧雨燕中工作
newuser.signUpInBackgroundWithBlock { (succeded, error) -> Void in
}
块的successed:Bool参数可能不是可选的,请尝试删除!。非常感谢你!第一行对我有用,我感谢你的帮助!