pars99 0 Junior Poster in Training

I keep running this code and it works until I press the button, findShapeCalc(), and then I get EXC_BAD_INSTRUCTION in the main.swift at the line NSApplicationMain(C_ARGC, C_ARGV). Why does this keep happening?

Code in question:

import Cocoa

class ViewController: NSViewController {
    @IBOutlet var dropDown : NSPopUpButton
    @IBOutlet var length : NSTextField
    @IBOutlet var label : NSTextField
    @IBOutlet var width : NSTextField

    @IBAction func findShapeCalc(sender : AnyObject) {
        dropDown.title.toInt()
        if dropDown.itemAtIndex(0){
            circle();
        }else if dropDown.itemAtIndex(1){
            rect();
        }
    }

    func circle(){
        var radius = (length.stringValue as NSString).floatValue
        var circumfrence = 2.0 * 3.14 * radius

        label.stringValue = "Circumfrence is \(circumfrence)"
    }

    func rect(){
        var rectLength = (length.stringValue as NSString).floatValue
        var rectWidth = (width.stringValue as NSString).floatValue

        var perimeter = (2.0 * rectLength) + (2.0 * rectWidth)

        label.stringValue = "Perimeter is \(perimeter)"
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }

    }


}

Sorry about posting Swift code here. Since there doesn't seem to be a section for Swift yet, this section seems the most suitable.

I've probably made many errors while writing the code, I'm just starting out. If you have sugestions on how to make the code better or more efficient, please tell me!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.