简体   繁体   中英

“(lldb)” error when running my program in swift

I am taking a course on Udemy to help learn iOS programming this winter and I am having trouble making this error go away. All the error tells me is "(lldb)" there is nothing else in the debugging box. However it does enter a break point after "if numberInt != nil {" here is my code:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var number: UITextField!

@IBOutlet weak var resultLabel: UILabel!

@IBAction func calculateButton(sender: AnyObject) {

    var numberInt = Int(number.text!)

    if numberInt != nil {

        var unwrappedNumber = numberInt!

        var isPrime = true

        if unwrappedNumber == 1 {

            isPrime = false

        }

        if unwrappedNumber != 2 && unwrappedNumber != 1 {

            for var i = 2; i < unwrappedNumber; i++ {

                if unwrappedNumber % i == 0 {

                    isPrime = false

                }

            }

        }

        if isPrime == true {

            resultLabel.text = "\(unwrappedNumber) is prime!"

        }
        else{

            resultLabel.text = "\(unwrappedNumber) is not prime!"

        }

    }

    else
    {

        resultLabel.text = "Please enter a number in the box"

    }

}
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

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

I am coding this in xCode and using swift not c#. This is my first time asking a question on here, I hope after some time practicing I will be able to help you guys out as well. If anyone would care to help me out learning the debugger on xCode that would be great too! Thanks, I appreciate the feedback!

change this

var unwrappedNumber = numberInt!

to

var unwrappedNumber = numberInt

and you no need exlamation mark after you check nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM