So my Swift program in Xcode 6.4 is working fine, until I click one of my buttons in particular. When I click it, the simulator crashes and the following is printed to the console:
2015-08-12 21:41:08.323 Unit Hero 2.0[2549:99472] -[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10
2015-08-12 21:41:08.326 Unit Hero 2.0[2549:99472] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Unit_Hero_2_0.ViewController finalUnitsButton:]: unrecognized selector sent to instance 0x7faf20675d10'
*** First throw call stack:
0 CoreFoundation 0x000000010b630c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d19bbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010b6380ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010b58e13c ___forwarding___ + 988
4 CoreFoundation 0x000000010b58dcd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010bed0d62 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010bfe250a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010bfe18d9 -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010bf1d958 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x000000010bf1e282 -[UIWindow sendEvent:] + 682
10 UIKit 0x000000010bee4541 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010bef1cdc _UIApplicationHandleEventFromQueueEvent + 18265
12 UIKit 0x000000010becc59c _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x000000010b564431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010b55a2fd __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010b559934 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010b559366 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010f604a3e GSEventRunModal + 161
18 UIKit 0x000000010becf8c0 UIApplicationMain + 1282
19 Unit Hero 2.0 0x000000010b4251c7 main + 135
20 libdyld.dylib 0x000000010d8d1145 start + 1
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
And here is the code for the button in question:
@IBAction func newCalculationButton(sender: AnyObject)
{
if (equation.count != 0) //empties arrays to prepare for a new calculation
{
equation.removeAll()
}
if (unitsOriginal.count != 0)
{
unitsOriginal.removeAll()
}
if (operations.count != 0)
{
operations.removeAll()
}
if (numerator.count != 0)
{
numerator.removeAll()
}
if (denominator.count != 0)
{
denominator.removeAll()
}
if (largestComponent.count != 0)
{
largestComponent.removeAll()
}
finalNumerator = nil
finalDenominator = nil
isNilNumerator = 0 //counter for number of nil items in numerator
isNilDenominator = 0 //counter for number of nil items in denominator
mainLabel.text = ""
}
What exception could it be referring to? The code is pretty simple, I'm not sure what could be wrong. Any insight is much appreciated!
Some times we copy paste button and Xcode keeps old references (actions and outlets). Check it: