I'm creating an app and trying to update a NSUserDefault from a a different view controller, although i don't think its the separate view controller thats doing it because i can't set a new NSUserDefault on this controller either. its crashing whenever i push the button, heres the code from the view controller:
// Upgrades.swift
// Unit3Final
//
// Created by fgstu on 4/14/16.
// Copyright © 2016 AllenH. All rights reserved.
//
import UIKit
class Upgrades: UIViewController {
var tapModifier = (NSUserDefaults.standardUserDefaults().integerForKey("tapModifier"))
func storeTheScore() {
NSUserDefaults.standardUserDefaults().setInteger(tapModifier, forKey: "tapModifier")
}
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.
}
#IBAction func BuyAHut(sender: UIButton) {
tapModifier += 5
storeTheScore()
}
}
it is set in my main view controller in my viewDidLoad with
var tapModifier: Int = 1
NSUserDefaults.standardUserDefaults().setInteger(tapModifier, forKey: "tapModifier")
and the error message is
2016-04-14 12:13:45.264 Unit3Final[40985:5120078] -[Unit3Final.Upgrades hutUpgrade:]: unrecognized selector sent to instance 0x7fadab4b2e80
2016-04-14 12:13:45.270 Unit3Final[40985:5120078] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Unit3Final.Upgrades hutUpgrade:]: unrecognized selector sent to instance 0x7fadab4b2e80'
*** First throw call stack:
(
0 CoreFoundation 0x000000010258de65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001042cddeb objc_exception_throw + 48
2 CoreFoundation 0x000000010259648d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001024e390a ___forwarding___ + 970
4 CoreFoundation 0x00000001024e34b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000102dac194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000102f1b6fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000102f1b9c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x0000000102f1aaf8 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x0000000102e1b49b -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x0000000102e1c1d0 -[UIWindow sendEvent:] + 865
11 UIKit 0x0000000102dcab66 -[UIApplication sendEvent:] + 263
12 UIKit 0x0000000102da4d97 _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x00000001024b9a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x00000001024af95c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x00000001024aee13 __CFRunLoopRun + 867
16 CoreFoundation 0x00000001024ae828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000106bcdad2 GSEventRunModal + 161
18 UIKit 0x0000000102daa610 UIApplicationMain + 171
19 Unit3Final 0x000000010201db7d main + 109
20 libdyld.dylib 0x0000000104ddf92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
It doesn't have a value, that's why it's crashing, try setting it to 0 initially.
You're adding 5 to nothing, instead of this,
tapModifier = NSUserDefaults etc...
try...
tapModifier = 0
Related
My app was working perfectly until I added an #IBAction. Now I just get this error:
2017-06-09 07:55:35.285 Press[1594:102051] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key add.'
* First throw call stack:
(
0 CoreFoundation 0x000000010724bb0b exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001044f3141 objc_exception_throw + 48
2 CoreFoundation 0x000000010724ba59 -[NSException raise] + 9
3 Foundation 0x0000000104008e8b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x0000000104b60644 -[UIViewController setValue:forKey:] + 87
5 UIKit 0x0000000104dcd6b9 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001071f1e8d -[NSArray makeObjectsPerformSelector:] + 269
7 UIKit 0x0000000104dcc06f -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x0000000104b66c73 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000104b67589 -[UIViewController loadView] + 177
10 UIKit 0x0000000104b678ba -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x0000000104b6810a -[UIViewController view] + 27
12 UIKit 0x0000000104a3063a -[UIWindow addRootViewControllerViewIfPossible] + 65
13 UIKit 0x0000000104a30d20 -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x0000000104a43b6e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x00000001049bd31f -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4346
16 UIKit 0x00000001049c3584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
17 UIKit 0x00000001049c0793 -[UIApplication workspaceDidEndTransaction:] + 182
18 FrontBoardServices 0x000000010895b5f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
19 FrontBoardServices 0x000000010895b46d -[FBSSerialQueue _performNext] + 186
20 FrontBoardServices 0x000000010895b7f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x00000001071f1c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
22 CoreFoundation 0x00000001071d70cf __CFRunLoopDoSources0 + 527
23 CoreFoundation 0x00000001071d65ff __CFRunLoopRun + 911
24 CoreFoundation 0x00000001071d6016 CFRunLoopRunSpecific + 406
25 UIKit 0x00000001049bf02f -[UIApplication _run] + 468
26 UIKit 0x00000001049c50d4 UIApplicationMain + 159
27 Press 0x0000000103f1a877 main + 55
28 libdyld.dylib 0x00000001081eb65d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is my Viewcontroller code:
import UIKit
class ViewController: UIViewController {
// OUTLETS
#IBOutlet weak var score: UILabel!
#IBAction func add(_ sender: Any) {
add()
}
// VARIABLES
var scoreVar = 0
let levelUpAt = [50, 100, 500, 1000, 5000, 10000, 50000, 100000]
var currentLevel = 1
var toAdd = 1
// OVERRIDES
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// FUNCTIONS
// Below code adds to the score
func add() {
scoreVar += 1 // Adds 1 to scoreVar
score.text = "scoreVar"; // Updates text to match
checkForLevelUp(); // Calls the function defined in the next few days ago
}
// Below code checks if the score meets the next level requirements
func checkForLevelUp() {
if (scoreVar - 1 < levelUpAt[currentLevel - 1]) { // Complicated math-y if statment
currentLevel += 1
toAdd += 1
}
}
}
It seems to be stuck on the class AppDelegate: UIResponder, UIApplicationDelegate { line on the AppDelegate, according to the debugger.
Go to your story board and click on the ViewController. Click one the Add button you created.
On the right side in the Outlet Inspector, remove anything mentioning the "Add" button.
Finally, recreate the outlets by option dragging from the button to your view controller and setting the type to "Action".
Why do I get a Thread:1 Signal SIGAGBRT within this code? I don't know what to change to fix the error. The application starts and as soon as I press the button the app cancels out and gives me an error.
import UIKit
class ViewController: UIViewController {
#IBOutlet var textFieldInput: UITextField!
#IBOutlet var laCelsius: UILabel!
#IBOutlet var laFahrenheit: 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 btn(sender: UIButton) {
var c_out = 0.0
var f_out = 0.0
var inputValue = 0.0
let textInput = NSString(string: textFieldInput.text!)
inputValue = textInput.doubleValue
c_out = (inputValue-32)*5/9
f_out = inputValue * 1.8 + 32
self.laCelsius.text = NSString(format: "%3.2f" ,c_out) as String
self.laFahrenheit.text = NSString(format: "%3.2f" ,f_out) as String
}
}
this is the error code:
2016-09-22 14:15:51.669 DegreeCL[19045:1774964] -[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40
2016-09-22 14:15:51.674 DegreeCL[19045:1774964] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance 0x7fa7bb643d40'
*** First throw call stack:
(
0 CoreFoundation 0x000000010de1dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fbc1deb objc_exception_throw + 48
2 CoreFoundation 0x000000010de26d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010dd6ccfa ___forwarding___ + 970
4 CoreFoundation 0x000000010dd6c8a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010e647a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010e7bae67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010e7bb143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000010e7ba263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010e6ba99f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010e6bb6d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010e666dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010e640553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x000000010dd43301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010dd3922c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010dd386e3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010dd380f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x00000001124b3ad2 GSEventRunModal + 161
18 UIKit 0x000000010e645f09 UIApplicationMain + 171
19 DegreeCL 0x000000010dc38412 main + 114
20 libdyld.dylib 0x000000011068592d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The crucial information is
[DegreeCL.ViewController btnPressed:]: unrecognized selector sent to instance ...'
That means in Interface Builder there is somewhere a dead connection to an action btnPressed. Remove it.
You can search for btnPressed with ⇧⌘F.
SIGABRIT - signal is sent due to many reasons but in this case i think you have problem with Memory.
You should turn on All Exeptions with option of po $arg1 it will identify the error.
Select your button from interface builder, then select connection inspector from utilities and check that if you have extra connected action method should be there, remove it by clicking x and your issue will be solved!
It's should be btnPressed as per your crash log!
This is the code that I tried running on Xcode and the idea is when I press the button, it will show the background and the logo, however when I press the button, it just leads me straight into the error
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var coolLogo: UIImageView!
#IBOutlet weak var coolBg: UIImageView!
#IBOutlet weak var uncoolButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
#IBAction func makeMeNotSoUncoolButton(sender: AnyObject) {
coolLogo.hidden = false
coolBg.hidden = false
uncoolButton.hidden = true
print ("Its running")
}
}
This is the error that I got
2016-06-29 10:19:01.229 SuperCool[1950:40240] -
[SuperCool.ViewController uncoolButton:]: unrecognized selector sent to instance 0x7fc4e9544fc0
2016-06-29 10:19:01.238 SuperCool[1950:40240] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SuperCool.ViewController uncoolButton:]: unrecognized selector sent to instance 0x7fc4e9544fc0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f617d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001113bbdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010f620d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f566cfa ___forwarding___ + 970
4 CoreFoundation 0x000000010f5668a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010fe41a8d -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010ffb4e67 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010ffb5143 -[UIControl _sendActionsForEvents:withEvent:] + 327
8 UIKit 0x000000010ffb4263 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010feb499f -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010feb56d4 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010fe60dc6 -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010fe3a553 _UIApplicationHandleEventQueue + 6660
13 CoreFoundation 0x000000010f53d301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010f53322c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010f5326e3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010f5320f8 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000113cadad2 GSEventRunModal + 161
18 UIKit 0x000000010fe3ff09 UIApplicationMain + 171
19 SuperCool 0x000000010f432422 main + 114
20 libdyld.dylib 0x0000000111e7f92d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like you connected either the uncoolButton outlet or the makeMeNotSoUncoolButton action incorrectly.
Just place brakepoint in that method and check your self class and class of your button, than you will know what isn't as you expected. You can check class using method class, that returns instance of your clas, than just print it to log.
This question already has answers here:
setValue:forUndefinedKey: this class is not key value coding-compliant for the key [duplicate]
(20 answers)
Closed 7 years ago.
I am very new to swift, extremely new, and I will probably feel like an idiot for asking this question. My very simple goal is that when my button is tapped the button's title will disappear, but unfortunately the app is crashing every time I run it and I don't know what I'm doing wrong. Thank you for the help.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var background1: UIImageView!
#IBOutlet weak var screenButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.screenButton.setTitle("Tap!", forState: UIControlState.Normal)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func screenTapped(sender: AnyObject) {
self.screenButton.setTitle("", forState: UIControlState.Normal)
}
}
2015-04-10 17:13:41.465 TopScore[6391:414281] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key screenTapped.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104fc0a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106b18bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000104fc06b9 -[NSException raise] + 9
3 Foundation 0x00000001053dbd43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000104f0a5e0 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x0000000105b1a4ed -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000105978a88 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x0000000105979078 -[UIViewController loadView] + 109
8 UIKit 0x00000001059792e9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010597977e -[UIViewController view] + 27
10 UIKit 0x0000000105898509 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x00000001058988a1 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x00000001058a4f8c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010584f0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x0000000105851e3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x0000000105850d35 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x00000001086ca243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x0000000104ef5c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x0000000104eeb9c5 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x0000000104eeb785 __CFRunLoopRun + 2389
20 CoreFoundation 0x0000000104eeabc6 CFRunLoopRunSpecific + 470
21 UIKit 0x00000001058507a2 -[UIApplication _run] + 413
22 UIKit 0x0000000105853580 UIApplicationMain + 1282
23 TopScore 0x0000000104de1cee top_level_code + 78
24 TopScore 0x0000000104de1d2a main + 42
25 libdyld.dylib 0x00000001072f4145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
At some point, you accidentally set up an outlet called screenTapped. You need to find that outlet in Interface Builder in your storyboard and delete it.
What you want is an action from the button to screenTapped:. An action and an outlet are two very different things.
So I went back and re-wrote my code and made sure the parameters were all in the right place. But now, when I run my app in iOS Simulator, I get a Thread 1:signal SIGABRT error and the following error in my Debug area:
2014-11-04 00:39:12.288 Juxta[60526:1144351] +[_TtCFC5Juxta14ViewController11viewDidLoadFS0_FT_T_L_7Counter parseClassName]: unrecognized selector sent to class 0x1059bb640
2014-11-04 00:39:12.291 Juxta[60526:1144351] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[_TtCFC5Juxta14ViewController11viewDidLoadFS0_FT_T_L_7Counter parseClassName]: unrecognized selector sent to class 0x1059bb640'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106c183f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108746bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000106c1f40d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000106b777fc ___forwarding___ + 988
4 CoreFoundation 0x0000000106b77398 _CF_forwarding_prep_0 + 120
5 Juxta 0x00000001057e2812 -[PFObject(Private) init] + 143
6 Juxta 0x00000001057d59f0 _TFCFC5Juxta14ViewController11viewDidLoadFS0_FT_T_L_7CountercfMS1_FT_S1_ + 64
7 Juxta 0x00000001057d5a32 _TFCFC5Juxta14ViewController11viewDidLoadFS0_FT_T_L_7CounterCfMS1_FT_S1_ + 50
8 Juxta 0x00000001057d44a7 _TFC5Juxta14ViewController11viewDidLoadfS0_FT_T_ + 1575
9 Juxta 0x00000001057d47f2 _TToFC5Juxta14ViewController11viewDidLoadfS0_FT_T_ + 34
10 UIKit 0x00000001075c7190 -[UIViewController loadViewIfRequired] + 738
11 UIKit 0x00000001075c738e -[UIViewController view] + 27
12 UIKit 0x00000001074e6db9 -[UIWindow addRootViewControllerViewIfPossible] + 58
13 UIKit 0x00000001074e7152 -[UIWindow _setHidden:forced:] + 276
14 UIKit 0x00000001074f365c -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010749e191 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
16 UIKit 0x00000001074a0e5c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
17 UIKit 0x000000010749fd22 -[UIApplication workspaceDidEndTransaction:] + 179
18 FrontBoardServices 0x000000010c3472a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
19 CoreFoundation 0x0000000106b4dabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
20 CoreFoundation 0x0000000106b43805 __CFRunLoopDoBlocks + 341
21 CoreFoundation 0x0000000106b435c5 __CFRunLoopRun + 2389
22 CoreFoundation 0x0000000106b42a06 CFRunLoopRunSpecific + 470
23 UIKit 0x000000010749f799 -[UIApplication _run] + 413
24 UIKit 0x00000001074a2550 UIApplicationMain + 1282
25 Juxta 0x00000001057d6e7e top_level_code + 78
26 Juxta 0x00000001057d6eba main + 42
27 libdyld.dylib 0x00000001097a8145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Here's my code just so it's more clear:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var testObject = PFObject(className: "TestObject")
testObject["foo"] = "bar"
testObject.saveInBackgroundWithTarget(nil, selector: nil)
class Counter : PFObject {
var voteCount: Int = 0
func incrementBy(amount: Int, numberOfTimes times: Int) { voteCount += amount * times
println(" \(voteCount) votes")
}
}
var countOption1 = PFObject(className: "countOption1")
countOption1 = Counter()
countOption1.saveInBackgroundWithTarget(PFObject.self, selector: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Any hint as to what could be wrong with my code? I was very careful this time.
You must have made some copy and paste mistake. There is no reason, for example, that:
class Counter is defined inside a UIViewController
class Counter has a didReceiveMemoryWarning function
Another class Counter in countOption1 function.
It is a mess