I'm creating a countdown timer for a game but I'm getting the SIGABRT error. I am coding in Swift 2. It countdowns from 45 seconds then has two other labels, one that is 5 seconds less, and the other 10 seconds less. The app opens up successfully in the simulator. Once I click on the screen then it crashes. I tried removing all the ties between the buttons/labels on the Storyboard to the ViewController.swift. Then, I re-"attached" them. The button has no text and is above everything. So, no matter where you tap on the screen, it will either start or reset. Once the button is clicked the NSTimer starts. Once the button is clicked again it resets the timer so its ready for the next time.
ViewController Code:
//
// ViewController.swift
// CS:GO C4 Timer
//
// Created by Panja on 11/14/15.
// Copyright © 2015 Panja. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var Main:Int = 0
var Kit:Int = 0
var NoKit:Int = 0
@IBOutlet weak var MainTime: UILabel!
@IBOutlet weak var DiffuseKit: UILabel!
@IBOutlet weak var NoDiffuseKit: UILabel!
var TimerCount = 0;
var TimerRunning = false;
var Timer = NSTimer();
var Toggle = false;
func Countdown(){
//Time Left Before Bomb Explodes
TimerCount = 45;
TimerCount -= 1
if(TimerCount <= 0){
MainTime.text = "No Time"
}else{
MainTime.text = "\(TimerCount)"
Main = TimerCount
}
//Time Left To Diffuse With A Kit
Kit = Main - 5
if(Kit <= 0){
DiffuseKit.text = "No Time"
}else{
DiffuseKit.text = "\(Kit)"
}
//Time Left To Diffuse Without A Kit
NoKit = Main - 10
if(NoKit <= 0){
NoDiffuseKit.text = "No Time"
}else{
NoDiffuseKit.text = "\(NoKit)"
}
}
@IBAction func ToggleButton(sender: AnyObject) {
//If The Button Is At Its Default at 45 Seconds & Not Running
if(Toggle == false){
if TimerRunning == false{
Timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true)
TimerRunning = true;
Toggle = true;
}
//If Timer is Running & Needs To Be Stopped
}else if (Toggle == true){
if TimerRunning == true{
Timer.invalidate()
TimerRunning = false
TimerCount = 45;
MainTime.text = "45"
Toggle = false;
}
}
}
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.
}
}
Error From Debug Console:
2015-11-15 12:20:54.288 CS:GO C4 Timer[32688:6460757] -[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00
2015-11-15 12:20:54.323 CS:GO C4 Timer[32688:6460757] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00'
*** First throw call stack:
(
0 CoreFoundation 0x00000001080849b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109c83deb objc_exception_throw + 48
2 CoreFoundation 0x000000010808cfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107fda9fa ___forwarding___ + 970
4 CoreFoundation 0x0000000107fda5a8 _CF_forwarding_prep_0 + 120
5 Foundation 0x000000010846b6f1 __NSFireTimer + 83
6 CoreFoundation 0x0000000107fe4de4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x0000000107fe4991 __CFRunLoopDoTimer + 1089
8 CoreFoundation 0x0000000107fa6331 __CFRunLoopRun + 1937
9 CoreFoundation 0x0000000107fa5918 CFRunLoopRunSpecific + 488
10 GraphicsServices 0x000000010c5ccad2 GSEventRunModal + 161
11 UIKit 0x00000001088a199e UIApplicationMain + 171
12 CS:GO C4 Timer 0x0000000107ea218d main + 109
13 libdyld.dylib 0x000000010a7de92d start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Main.Storyboard Image of The Main Storyboard
Thread 1 - 12 Main Picture of the Thread 1 file that shows when the application crashes
The problem is that Counting
and Countdown
are two different words.