Thread 1: signal SIGABRT error due to Button - swift

I am still learning swift and Xcode so please explain as much as possible in layman's terms so i can understand and try to fix this issue, i'm getting a sigbrt error, but not sure why. Ive created tons of buttons and linked it to the viewcontroller.swift which i have done, but for the life of me, i can not see why i am getting this error. Any help would be very much appreciated.
First here is the debug error:
2018-11-26 20:30:42.713790+0000 Numbers[2058:130834] -[Numerology.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0
2018-11-26 20:30:42.724547+0000 Numbers[2058:130834] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Numbers.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107e6a1bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000106448735 objc_exception_throw + 48
2 CoreFoundation 0x0000000107e88f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x000000010a823b4a -[UIResponder doesNotRecognizeSelector:] + 287
4 CoreFoundation 0x0000000107e6eed6 ___forwarding___ + 1446
5 CoreFoundation 0x0000000107e70da8 _CF_forwarding_prep_0 + 120
6 UIKitCore 0x000000010a7f6ecb -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKitCore 0x000000010a2320bd -[UIControl sendAction:to:forEvent:] + 67
8 UIKitCore 0x000000010a2323da -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKitCore 0x000000010a23131e -[UIControl touchesEnded:withEvent:] + 583
10 UIKitCore 0x000000010a8320a4 -[UIWindow _sendTouchesForEvent:] + 2729
11 UIKitCore 0x000000010a8337a0 -[UIWindow sendEvent:] + 4080
12 UIKitCore 0x000000010a811394 -[UIApplication sendEvent:] + 352
13 UIKitCore 0x000000010a8e65a9 __dispatchPreprocessedEventFromEventQueue + 3054
14 UIKitCore 0x000000010a8e91cb __handleEventQueueInternal + 5948
15 CoreFoundation 0x0000000107dcf721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000107dcef93 __CFRunLoopDoSources0 + 243
17 CoreFoundation 0x0000000107dc963f __CFRunLoopRun + 1263
18 CoreFoundation 0x0000000107dc8e11 CFRunLoopRunSpecific + 625
19 GraphicsServices 0x000000010ff861dd GSEventRunModal + 62
20 UIKitCore 0x000000010a7f581d UIApplicationMain + 140
21 Numbers 0x0000000105b17ed7 main + 71
22 libdyld.dylib 0x0000000109303575 start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Below is My Code:
import UIKit
class twoViewController: UIViewController {
let ballArray = ["brownBall1","brownBall2","bbrownBall3","brownBall4","brownball5","lightBlue6","lightBlue7","lightBlue8","lightBlue9","lightBlue10","yellowBall11","yellowBall12","yellowBall13","yellowBall14","yellowball15","silverBall16","silverBall17","silverBall18","silverBall19","silverBall20","redBall21","redBall22","redBall23","redBall24","redBall25","purpleBall26","purpleBall27","purpleBall28","purpleBall29","purpleBall30","greenBall31","greenball32","greenball33","greenball34","greenBall35","goldBall36","goldBall37","goldBall38","goldBall39","goldBall40","blueBall41","blueBall42","blueBall43","blueBall44","blueball45","blackBall46","blackBall47","blackBall48","blackBall49","blackBall50"]
let luckyStarArray = ["goldOne", "goldTwo", "goldThree", "goldFour", "goldFive", "goldSix", "goldSeven", "goldEight", "goldBballNine"]
#IBOutlet weak var starView1: UIImageView!
#IBOutlet weak var starView2: UIImageView!
#IBOutlet weak var starView3: UIImageView!
#IBOutlet weak var starView4: UIImageView!
#IBOutlet weak var starView5: UIImageView!
#IBOutlet weak var luckyStar1: UIImageView!
#IBOutlet weak var luckyStar2: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
func generateYourNumbersButtonPress(_ sender: UIButton) {
let shuffledBallArray = ballArray.shuffled()
starView1.image = UIImage(named: shuffledBallArray[0])
starView2.image = UIImage(named: shuffledBallArray[1])
starView3.image = UIImage(named: shuffledBallArray[2])
starView4.image = UIImage(named: shuffledBallArray[3])
starView5.image = UIImage(named: shuffledBallArray[4])
let shuffledLuckyBallArray = luckyStarArray.shuffled()
luckyStar1.image = UIImage(named: shuffledLuckyBallArray[0])
luckyStar2.image = UIImage(named: shuffledLuckyBallArray[1])
}
}
}

First, don't put generateYourNumbersButtonPress inside of viewDidLoad.
Second, mark generateYourNumbersButtonPress as an #IBAction.
Third, reconnect the action to the button after fixing the above two issues so you connect the proper action method to the button's event.

Related

Function to decrement label does not work [duplicate]

I am making an app that requires a user to press one of two UIButtons and then prints a response depending on which button was pressed (determined based on the tag of the button pressed). However, when I run press button, I get an
Unrecognized selector sent to instance
How do I resolve this?
Here's my code. The IBAction at the bottom refers to the UIButtons that are causing the error:
import UIKit
class ViewController: UIViewController {
let story1 = "This is the story."
let answer1 = "No change"
let answer2 = "Lose 1 health"
var healthStat : Int = 10
#IBOutlet weak var storyText: UILabel!
#IBOutlet weak var health: UILabel!
#IBOutlet weak var restartButton: UILabel!
#IBOutlet weak var choiceOne: UIButton!
#IBOutlet weak var choiceTwo: UIButton!
var storyIndex = 1
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
storyText.text = story1
choiceOne.setTitle("\(answer1)", for: .normal)
choiceTwo.setTitle("\(answer2)", for: .normal)
health.text = String("Health: \(healthStat)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func buttonPressed(_ sender: UIButton) {
if sender.tag == 1 {
print("Option 1 selected")
}
else if sender.tag == 2 {
print("Option 2 selected. Lose 1 health.")
healthStat = healthStat - 1
}
}
}
Here is the entirety of the error:
2017-07-29 21:45:24.626 Choose Your Own Adventure[16001:694686] -[Choose_Your_Own_Adventure.ViewController buttonOnePressed:]: unrecognized selector sent to instance 0x7fc199c0cfe0
2017-07-29 21:45:24.638 Choose Your Own Adventure[16001:694686] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Choose_Your_Own_Adventure.ViewController buttonOnePressed:]: unrecognized selector sent to instance 0x7fc199c0cfe0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000113504b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011037e141 objc_exception_throw + 48
2 CoreFoundation 0x0000000113574134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000011348b840 ___forwarding___ + 1024
4 CoreFoundation 0x000000011348b3b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000110c66d82 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000110deb5ac -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000110deb8c7 -[UIControl _sendActionsForEvents:withEvent:] + 450
8 UIKit 0x0000000110dea802 -[UIControl touchesEnded:withEvent:] + 618
9 UIKit 0x0000000110cd47ea -[UIWindow _sendTouchesForEvent:] + 2707
10 UIKit 0x0000000110cd5f00 -[UIWindow sendEvent:] + 4114
11 UIKit 0x0000000110c82a84 -[UIApplication sendEvent:] + 352
12 UIKit 0x00000001114665d4 __dispatchPreprocessedEventFromEventQueue + 2926
13 UIKit 0x000000011145e532 __handleEventQueue + 1122
14 CoreFoundation 0x00000001134aac01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001134900cf __CFRunLoopDoSources0 + 527
16 CoreFoundation 0x000000011348f5ff __CFRunLoopRun + 911
17 CoreFoundation 0x000000011348f016 CFRunLoopRunSpecific + 406
18 GraphicsServices 0x000000011542da24 GSEventRunModal + 62
19 UIKit 0x0000000110c65134 UIApplicationMain + 159
20 Choose Your Own Adventure 0x000000010fd9efa7 main + 55
21 libdyld.dylib 0x00000001144a465d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
It seems like you have rename your IBAction method name earlier it was different and it is connected to the previous name inside your storyboard. So just disconnect your action method and reconnect it appropriately.

How can I stop my swift app from crashing in simulator [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 6 years ago.
I am trying to build a tip calculator using swift 3 and Xcode. I have written a function and I am trying to simply test that and make sure it is doing what it should and I'll worry about formatting later. However, even without any build or run errors it crashes when I try to run it in the simulator. In regards to whatever answers I may receive, I am very new to this and my teacher doesn't have us using a book so I am not very familiar with the correct terminology. I have pasted my code and the crash log.
//
// ViewController.swift
// myTipCalculator
//
// Created by Mac User on 2/11/17.
// Copyright © 2017 Mac User. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var billAmount: UITextField!
#IBOutlet weak var fifteenTip: UIButton!
#IBOutlet weak var twentyTip: UIButton!
#IBOutlet weak var twentyFiveTip: UIButton!
#IBOutlet weak var tipTotal: UILabel!
#IBOutlet weak var grandTotal: 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.
}
func calcTip(num1: Double, num2: Double){
print("Tip: \(num1 * num2)")
}
#IBAction func calcFifteen(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.15
calcTip(num1: billA!, num2: tipA)
}
#IBAction func calcTwenty(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.20
calcTip(num1: billA!, num2: tipA)
}
/*#IBAction func calcTwentyFive(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.25
calcTip(num1: billA!, num2: tipA)
}*/
}
2017-02-11 18:56:21.596 myTipCalculator[7087:101844] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<myTipCalculator.ViewController 0x7f89d3807b80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calcTwentyFive.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108692d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010590b21e objc_exception_throw + 48
2 CoreFoundation 0x0000000108692c99 -[NSException raise] + 9
3 Foundation 0x00000001054199df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000105f75293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x00000001061e979e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001086379e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x00000001061e8122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000105f7b9c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000105f7c2e7 -[UIViewController loadView] + 177
10 UIKit 0x0000000105f7c61c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x0000000105f7ce70 -[UIViewController view] + 27
12 UIKit 0x0000000105e464b5 -[UIWindow addRootViewControllerViewIfPossible] + 71
13 UIKit 0x0000000105e46c06 -[UIWindow _setHidden:forced:] + 293
14 UIKit 0x0000000105e5a519 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000105dd2f8d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
16 UIKit 0x0000000105dd90ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
17 UIKit 0x0000000105dd626d -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000109dce6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x0000000109dce544 -[FBSSerialQueue _performNext] + 189
20 FrontBoardServices 0x0000000109dce8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000108637761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010861c98c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x000000010861be76 __CFRunLoopRun + 918
24 CoreFoundation 0x000000010861b884 CFRunLoopRunSpecific + 420
25 UIKit 0x0000000105dd4aea -[UIApplication _run] + 434
26 UIKit 0x0000000105ddac68 UIApplicationMain + 159
27 myTipCalculator 0x000000010532860f main + 111
28 libdyld.dylib 0x000000010963c68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Try to remove the comments from this action: calcTwentyFive, and run your App. If that didn't help you, check out all of your outlets and actions.
It seems that you forgot to list one of your actions/outlet in UIViewController. Basically, click on each item you have in Main.StoryBoard, and click the arrow to the right to check the connection as the following image:
Make sure all of your outlets and actions are found in UIViewController.

Swift 3 - Thread 1: Signal SIGABRT Unrecognised selector sent to Instance

could any please help me solve this problem? I have been at it trying to fix the issue for a few hours but nothing has worked so far. Everytime I click a button it immediately leads to the error Thread 1: Signal SIGABRT.
This is the code (Note: It is still a work in Progress):
import UIKit
class ViewController: UIViewController {
#IBOutlet var Sec1: UILabel!
#IBOutlet var Sec2: UILabel!
#IBOutlet var Sec3: UILabel!
#IBOutlet var Sec4: UILabel!
#IBOutlet var Sec5: UILabel!
#IBOutlet var Sec6: UILabel!
#IBOutlet var Sec7: UILabel!
#IBOutlet var Sec8: UILabel!
#IBOutlet var Sec9: 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.
}
var x = 2
// if (x%2 == 0) {
#IBAction func ButtonPressed(Button1: UIButton) {
Sec1.text = "X"
}
}
This is the Error:
**2017-02-23 07:58:14.194 Tic Tac Toe IS[46707:2457511] -[Tic_Tac_Toe_IS.ViewController ButtonPressed:]: unrecognized selector sent to instance 0x7fb8a8d04ee0
2017-02-23 07:58:14.202 Tic Tac Toe IS[46707:2457511] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Tic_Tac_Toe_IS.ViewController ButtonPressed:]: unrecognized selector sent to instance 0x7fb8a8d04ee0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bebfd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001092be21e objc_exception_throw + 48
2 CoreFoundation 0x000000010bf2ff04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010be45005 ___forwarding___ + 1013
4 CoreFoundation 0x000000010be44b88 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010978f8bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000109915c38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000109915f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000109914e4d -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x00000001097fd545 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x00000001097fec33 -[UIWindow sendEvent:] + 4011
11 UIKit 0x00000001097ab9ab -[UIApplication sendEvent:] + 371
12 UIKit 0x0000000109f9872d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x0000000109f91463 __handleEventQueue + 4879
14 CoreFoundation 0x000000010be64761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010be4998c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010be48e76 __CFRunLoopRun + 918
17 CoreFoundation 0x000000010be48884 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x000000010ddf9a6f GSEventRunModal + 161
19 UIKit 0x000000010978dc68 UIApplicationMain + 159
20 Tic Tac Toe IS 0x0000000108cdb7af main + 111
21 libdyld.dylib 0x000000010ce6f68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)**
Could you check the connection between your #IBAction func ButtonPressed() with storyboard? You can check it from the "Connection inspector" on the storyboard.

NSUnknownKeyException - Xcode

My program shows this problem. Can anybody tell me what's wrong?
"2016-08-26 17:21:00.548 SegundaTentativa[2347:203583] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010786dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109611deb objc_exception_throw + 48
2 CoreFoundation 0x000000010786d9c9 -[NSException raise] + 9
3 Foundation 0x0000000107c3f19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000108228d0c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010845f7fb -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001077a7890 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010845e1de -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x000000010822f8d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000108230202 -[UIViewController loadView] + 178
10 UIKit 0x0000000108230560 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000108230cd3 -[UIViewController view] + 27
12 UIKit 0x0000000108106fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x000000010810769d -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000108119180 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010808ded9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000108094568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
17 UIKit 0x0000000108091714 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x000000010b4a28c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000010b4a2741 -[FBSSerialQueue _performNext] + 178
20 FrontBoardServices 0x000000010b4a2aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000107793301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010778922c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x00000001077886e3 __CFRunLoopRun + 867
24 CoreFoundation 0x00000001077880f8 CFRunLoopRunSpecific + 488
25 UIKit 0x0000000108090f21 -[UIApplication _run] + 402
26 UIKit 0x0000000108095f09 UIApplicationMain + 171
27 SegundaTentativa 0x0000000107688432 main + 114
28 libdyld.dylib 0x000000010a0d592d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) "
ViewController:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var lbTexto: UILabel!
#IBOutlet weak var imgQuadro: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lbTexto.text = "Que jogador de vôlei e?"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func ChangeText(sender: AnyObject) {
lbTexto.text = "Ricardinho"
}
#IBAction func HiddenQuadro(sender: AnyObject) {
imgQuadro.hidden = true
}
/*#IBAction func TesteSimbora(sender: UIButton) {
lbText.text = "Ricardinho"
}
#IBAction func EscondeQuadro(sender: UIButton) {
imQuadro.hidden = true
}*/
}
Pay attention to error message:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'
Something tries to set non-existing imQuadro property of your view controller, and from stack trace mentioning outlets it probably happens when controller is loaded from storyboard/xib.
Most likely you have wrong outlet connection set in interface builder, that might happen if you initially created outlet with name imQuadro and then manually fixed it to imgQuadro only in your code.

Getting a Swift run-time error (NSException)

I'm relatively new to Swift programming and I'm getting a run-time that is irking me quite a bit and I'm not sure why this is occurring as the source code looks correct.
The run-time error leads me to this in the console:
'[<UIViewController 0x7ff27051a5f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btnRoll.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103744e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105484deb objc_exception_throw + 48
2 CoreFoundation 0x0000000103744aa9 -[NSException raise] + 9
3 Foundation 0x0000000103b0d9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x00000001040f0320 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010431ef41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001036854a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010431d924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x00000001040f6eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x00000001040f7816 -[UIViewController loadView] + 178
10 UIKit 0x00000001040f7b74 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x00000001040f82e7 -[UIViewController view] + 27
12 UIKit 0x0000000103fceab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000103fcf199 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000103fe0c2e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000103f59663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000103f5fcc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
17 UIKit 0x0000000103f5ce7b -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000107319754 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000107319ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000103670a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010366695c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x0000000103665e13 __CFRunLoopRun + 867
23 CoreFoundation 0x0000000103665828 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000103f5c7cd -[UIApplication _run] + 402
25 UIKit 0x0000000103f61610 UIApplicationMain + 171
26 Craps 0x00000001035652dd main + 109
27 libdyld.dylib 0x0000000105f8d92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I only have 30 lines of code or so in the mini-game I created and I don't see why the error is coming up:
//
// ViewController.swift
// Craps
//
// Created by Lamido Tijjo on 2/11/16.
// Copyright © 2016 YauwaSarki. All rights reserved.
//
import UIKit
class CrapsViewController: UIViewController {
var rollDice1: Int = 0
var rollDice2: Int = 0
var rollTotal: Int = 0
#IBOutlet var lblRollOne: UILabel!
#IBOutlet var lblRollTwo: UILabel!
#IBOutlet var lblTotalRoll: UILabel!
#IBAction func btnRollDice(sender: AnyObject) {
rollDice1 = Int(arc4random() % 6) + 1
rollDice2 = Int(arc4random() % 6) + 1
rollTotal = rollDice1 + rollDice2
lblRollOne.text = String(rollDice1)
lblRollTwo.text = String(rollDice2)
if rollTotal != 7 || rollTotal != 11 {
lblTotalRoll.text = "Sorry you rolled a \(rollTotal), please try again!"
} else {
lblTotalRoll.text = "Congrats! you rolled a \(rollTotal), play again if you like!"
}
}
}
Can someone or some people please kindly shed some light on the situation. Thanks!
You have outlets defined for your view controller in a storyboard or .xib file. One of them is called "btnRoll" and was linked to the controller at some point. The matching property does not exist in code.
Possible reasons are: you deleted the code without unlinking the outlet or you have the wrong view controller defined as the view's owner.