代码在Xcode升级之前正在运行

时间:2015-04-13 21:38:01

标签: ios xcode swift

这段代码上周正在运行,然后我在周末更新了Xcode。现在我收到以下错误:

Class 'TransactionsViewController' has no initializers. 

我正在使用Xcode 6.3。我已经将转换例程运行到最新版本的Swift但它没有帮助。

class TransactionsViewController: UIViewController {

// a function to call when an alert message is needd
func displayAlert(title:String, error:String) {
    var alert = UIAlertController(title: title, message: alertError, preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: {action in
        self.dismissViewControllerAnimated(true, completion: nil)
    }))
    self.presentViewController(alert, animated: true, completion: nil)

}

var alertError = ""
var segueName = ""

//var userInfo = ["User Name: \loginEntered"]

var knownUser:Bool


/*

Check hasLoggedInBefore to determine if user has logging in before
If he has not, load to persistent storage
    traSeason
    traDispensingPhysicinan (array)
    traACT (array)
    traSport (array)
    traInsuranceCode (array)
    traBodyPart (array)
    traDispenseToPersonnelID (array)
    traDispenseToPhysicianID (array)

    loggedInUserName

var knownUser = true

*/

//function to call the segue named in var segueName
func doSegue () {

    performSegueWithIdentifier(segueName, sender: self)

}

@IBAction func dispenseButton(sender: AnyObject) {

    segueName = "goToDispenseScreenOne"

    /*
    Load team medication information into var before calling segue

        -Team ID
        -Current date
        -Current team season
        -Sport List


    Additional items to have ready for the next screen

        -Roster
        -Inventory in stock
        -Physician list
        -ATC (user) list

    Items for next screen

        -Insurance list (constant)
        -Body part list (constant)
    */

    doSegue()

}

@IBAction func intoStockButton(sender: AnyObject) {

    //segueName = "goToIntoStockScreenOne"

    //set the error message
    self.alertError = "This function is not ready yet."

    //Display the error message on screen
    self.displayAlert("Ooops", error: alertError)

    /*  

    */

    //doSegue()

}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// 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.
}
*/

}

UIKit

class TransactionsViewController: UIViewController { }

1 个答案:

答案 0 :(得分:0)

正如我在评论中所猜测的那样,您已将此作为实例属性编写:

var knownUser:Bool

但是您没有分配初始值,因此它未初始化。因此,您的代码是非法的,因为您也没有初始化方法。

顺便说一句,这个代码在Swift 1.1中是合法的,但在Swift 1.2中则不合适。如果没有初始化程序,它将永远是非法的。

另一方面,此属性声明是合法的,因为它提供了初始值:

var knownUser = true

但你评价了它。