1
var lastnumber: String = ""
@IBOutlet var anserField : UILabel                           Thread 1: breakpoint 2.4
@IBOutlet var operatorLable: UILabel
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.
}

@IBAction func buttonTapped(TheButton: UIButton) {
    if anserField.text == "0" {
        anserField.text = TheButton.titleLabel.text
    } else {
    anserField.text = anserField.text + TheButton.titleLabel.text
    }
    println(TheButton.titleLabel.text);
}

@IBAction func plusTapped(TheButton: UIButton) {
 println("plus tapped")
    if operatorLable.text == "" {
        operatorLable.text = "+"
        lastnumber = anserField.text
        anserField.text = "0"
    }else {
        enterTapped(nil)
        operatorLable.text = "+"
    }
}

@IBAction func minusTapped(TheButton: UIButton) {
    println("minus tapped")
    if operatorLable.text == "" {
        operatorLable.text = "-"
        lastnumber = anserField.text
        anserField.text = "0"
    }else {
    enterTapped(nil)
        operatorLable.text = "-"
    }
}
@IBAction func cleartapped(AnyObject) {
anserField.text = "0"
    operatorLable.text = ""
    lastnumber = ""
 }

@IBAction func enterTapped(AnyObject?) {
    var num1 = lastnumber.toInt()
    var num2 = anserField.text.toInt()
    if !num1 || !num2 {
    ShowError()
        return
    }
    var anser = 0
    if operatorLable.text == "-" {
   anser = num1! - num2!
    } else if operatorLable.text == "+" {
       anser = num1! + num2!
    } else {
ShowError()
return

    }
    println(anser)
}
func ShowError(){
// to do this
    println("there was a error")
}

}

I need help i am new to swift and coding and i am not to god to be honest i can't figure out what is won't with my code please help! (error is at the top just look on the right) I am coding a calculator(don't know if that helps but why not) and it is a error that i just can't fix i have tried many things but none of it is working it is a single view application for the iPhone 5s and this code is from the viewcontroler. swift this is the decoder and self things if they useful

aDecoder    Swift.ImplicitlyUnwrappedOptional<Foundation.NSCoder>   0x00007f829b04fe00  0x00007f829b04fe00
Some    UINibDecoder *  0x00007f829b04fe00  0x00007f829b04fe00
[0] UINibDecoder        
self    calculater.ViewController   0x00007f829a58a980  0x00007f829a58a980
UIKit.UIViewController  UIKit.UIViewController      
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject     
lastnumber  Swift.String    unable to read data 
core    Swift._StringCore       
_baseAddress    Swift.COpaquePointer    0x00000001078bd538  0x00000001078bd538 calculater.__TEXT.__ustring + 40
value   Builtin.RawPointer  0x1078bd538 0x00000001078bd538 calculater.__TEXT.__ustring + 40
_countAndFlags  Swift.UWord 9223372036854775808 -9223372036854775808
value   Builtin.Word    -9223372036854775808    -9223372036854775808
_owner  Swift.Optional<AnyObject>   nil None
anserField  @sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>      
Some    UIKit.UILabel       
UIKit.UIView    UIKit.UIView        
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject     
operatorLable   @sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>      
Some    UIKit.UILabel       
UIKit.UIView    UIKit.UIView        
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject 

please put in the comment if you need anything else to figure out the problem

this is what hapend when i turned off the breakpoints and i pressed certain buttons (more info in comments)

2014-08-22 23:39:05.613 calculater[6307:2641435] -[_TtC10calculater14ViewController plusTapped:]: unrecognized selector sent to instance 0x7faad9dbd150 2014-08-22 23:39:05.617 calculater[6307:2641435] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC10calculater14ViewController plusTapped:]: unrecognized selector sent to instance 0x7faad9dbd150' * First throw call stack: ( 0 CoreFoundation 0x00000001070f5055 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000108bafa1c objc_exception_throw + 45 2 CoreFoundation 0x00000001070fbf1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000107054dbc ___forwarding_ + 988 4 CoreFoundation 0x0000000107054958 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000107974196 -[UIApplication sendAction:to:from:forEvent:] + 75 6 UIKit 0x0000000107a78c80 -[UIControl _sendActionsForEvents:withEvent:] + 467 7 UIKit 0x0000000107a7804f -[UIControl touchesEnded:withEvent:] + 522 8 UIKit 0x00000001079b9368 -[UIWindow _sendTouchesForEvent:] + 735 9 UIKit 0x00000001079b9c93 -[UIWindow sendEvent:] + 683 10 UIKit 0x0000000107986f51 -[UIApplication sendEvent:] + 246 11 UIKit 0x0000000107993ec6 _UIApplicationHandleEventFromQueueEvent + 17699 12 UIKit 0x000000010796fcd9 _UIApplicationHandleEventQueue + 1967 13 CoreFoundation 0x000000010702b0b1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 14 CoreFoundation 0x000000010702099d __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x000000010701ffd4 __CFRunLoopRun + 868 16 CoreFoundation 0x000000010701fa06 CFRunLoopRunSpecific + 470 17 GraphicsServices 0x000000010adbeabf GSEventRunModal + 161 18 UIKit 0x0000000107972cf8 UIApplicationMain + 1282 19 calculater 0x0000000106c7f6ed top_level_code + 77 20 calculater 0x0000000106c7f72a main + 42 21 libdyld.dylib 0x0000000109120145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

ns parkour
  • 11
  • 3
  • Perhaps you did set a breakpoint? Type "breakpoint list" in the debugger console or go to the Breakpoint Navigator (cmd-7). – Martin R Aug 23 '14 at 05:16
  • @Anbu.Karthik: Please note that the backticks are for `code`, not for general emphasis. There is no reason to write "Swift" as `swift` or "iPhone 5s" as `iPhone 5s` . – Martin R Aug 23 '14 at 05:19
  • OK then what do I do I am there but I don't know what you mean I am a beginner and I do not know much I see the breakpoints but I am still confused – ns parkour Aug 23 '14 at 06:34
  • I tried turning the breakpoints and then this hapend – ns parkour Aug 23 '14 at 06:35
  • import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? 2014-08-22 23:36:20.584 calculater[6307:2641435] Failed to set (keyPath) user defined inspected property on (UIButton): [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath. – ns parkour Aug 23 '14 at 06:36
  • and when i presed some buttens it just crashed and – ns parkour Aug 23 '14 at 06:38
  • this happend import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? – ns parkour Aug 23 '14 at 06:38
  • it said (i put it in the auvtural thing it is the last one) – ns parkour Aug 23 '14 at 06:40

0 Answers0