我正在使用 xcode 和 swift 上的解析设置我的注册和登录页面,但我不断收到致命错误。有人可以看到我做错了什么吗?

I am setting up my sign up and login page using parse on xcode with swift but i keep getting a fatal error. Can somebody see what im doing wrong?

这是我目前所拥有的:

import Foundation
import Parse
import UIKit
import Bolts

class SignUpViewController: UIViewController, UITextFieldDelegate {


    @IBOutlet weak var statusLabel: UILabel!


    @IBOutlet weak var emailTextField: UITextField!


    @IBOutlet weak var passwordTextField: UITextField!


    @IBOutlet weak var createAccountButton: UIButton!


    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! as String)

        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

        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) as String
                }
                else
                {
                    // No userInfo dictionary present
                    // Help from 
                }
            }
        }
    }

    func textFieldShouldReturn(textField: UITextField) -> Bool
    {
        textField.resignFirstResponder()
        return true;
    }
}

当我 运行 时,我在 xcode 的终端中收到此消息:

fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) 

并以绿色突出显示的是:

var validDomainsFileContent = NSString(contentsOfFile: validDomainsFileLocation!, encoding: NSUTF8StringEncoding, error: nil)

我该怎么做才能避免这个错误? 我正在尝试创建一个使用 parse 中的 emailVerified 功能的登录名,但我一直收到此错误并且无法将电子邮件保存到核心或将验证电子邮件发送给用户。我该怎么做才能使此代码正常工作并阻止错误出现?

在这种情况下,找不到 validDominsfileContent 中的文件。您需要确保该文件包含在您的 Bundle 中。

为此,打开 Bundle-Resources:

Project > App target > Build Phases > Copy bundle resources

保存文件。现在它应该被 Swift.

找到了