0

I'm just starting to learn some ios development in Xcode and I am following an online tutorial. It seems though that very regularly my app crashes when I run it and I get the dreaded Signal SIGABRT error.

For example, I have this code:

import UIKit

class ViewController: UIViewController {

    @IBAction func camera(_ sender: Any) {
        print("hello")
    }

    func processTimer() {
        print("a second has passed!")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var timer = Timer()

        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: Selector("processTimer"), userInfo: nil, repeats: true)
        // Do any additional setup after loading the view.
    }
}

Now, prior to adding the timer part, the app opened fine. As soon as I added the timer, it creates this crash. The only way I seem to be able to resolve is by deleting the button, but obviously as I start to create proper apps, this will be a real pain.

This same thing has happened a lot to me already where the app works, I add some code and then suddenly I get this error. Could somebody explain what it is I am doing wrong here and how I can fix without deleting the button each time?

Cœur
  • 37,241
  • 25
  • 195
  • 267
DevB1
  • 1,235
  • 3
  • 17
  • 43
  • That's some pretty out-of-date Swift code. What version of Xcode and Swift are you trying to use? – rmaddy Jun 11 '19 at 21:19
  • Oh really? I'm on 10.2.1 – DevB1 Jun 11 '19 at 21:21
  • Is the `@IBAction` hooked up correctly? – Chris Jun 11 '19 at 21:22
  • You need to mark `processTimer` as `@objc` in order to use as a selector, but your `Selector` syntax shows that you're using quite an old Swift version, so you should specify which one. You should also make sure the `timer` is actually stored in memory and released before you invalidate it, so you should store it as an instance property rather than a local variable. – Dávid Pásztor Jun 11 '19 at 21:24

0 Answers0