Alex Kristensen Alex Kristensen - 1 year ago 68
iOS Question

My app is simple app is crashing

I have made a small program which I use to count the money in the safe at work. But after updating my iPhone it crashes. I have tried a lot but can't find a solution.

The crash happens when I press the button which activates the following function:

@IBAction func Knap(sender: AnyObject) {}

I'm very new to coding so please keep the answers as simple as possible :)

My app is as follows:

// ViewController.swift
// Pengeskabstæller
// Created by Alex on 09/07/2016.
// Copyright © 2016 Alex. All rights reserved.

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var In50B: UITextField!
@IBOutlet weak var In50L: UITextField!
@IBOutlet weak var In20B: UITextField!
@IBOutlet weak var In20L: UITextField!
@IBOutlet weak var In10B: UITextField!
@IBOutlet weak var In10L: UITextField!
@IBOutlet weak var In5B: UITextField!
@IBOutlet weak var In5L: UITextField!
@IBOutlet weak var In2B: UITextField!
@IBOutlet weak var In2L: UITextField!
@IBOutlet weak var In1B: UITextField!
@IBOutlet weak var In1L: UITextField!
@IBOutlet weak var In05B: UITextField!
@IBOutlet weak var In05L: UITextField!
@IBOutlet weak var Ialt: UILabel!

override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.


override func didReceiveMemoryWarning() {
// Dispose of any resources that can be recreated.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

@IBAction func Knap(sender: AnyObject) {
//Hvad knappen gør

//Ganger input ved værdi af bundt eller løse
var x50B: Int = Int(In50B.text!)!
x50B = x50B*5000
var x50L:Int = Int(In50L.text!)!
x50L = x50L*500
var x20B:Int = Int(In20B.text!)!
x20B = x20B*4000
var x20L:Int = Int(In20L.text!)!
x20L = x20L*400
var x10B:Int = Int(In10B.text!)!
x10B = x10B*2000
var x10L:Int = Int(In10L.text!)!
x10L = x10L*200
var x5B:Int = Int(In5B.text!)!
x5B = x5B*1000
var x5L:Int = Int(In5L.text!)!
x5L = x5L*200
var x2B:Int = Int(In2B.text!)!
x2B = x2B*500
var x2L:Int = Int(In2L.text!)!
x2L = x2L*50
var x1B:Int = Int(In1B.text!)!
x1B = x1B*500
var x1L:Int = Int(In1L.text!)!
x1L = x1L*50
var x05B:Int = Int(In05B.text!)!
x05B = x05B*200
var x05L:Int = Int(In05L.text!)!
x05L = x05L*20

//Lægger det hele sammen

let penge1 = (x50B + x50L + x20B)
let penge2 = (x20L + x10B + x10L)
let penge3 = (x5B + x5L + x2B + x2L)
let penge4 = (x1B + x1L + x05B + x05L)
let penge99 = String(penge1+penge2+penge3+penge4)

//Printer ialt
Ialt.text = penge99


The crash notes is:

2016-10-30 01:13:57.687826 Pengeskabstæller[879:222437] -[Pengeskabstæller.ViewController Knap:]: unrecognized selector sent to instance 0x13fe0aac0
2016-10-30 01:13:57.688704 Pengeskabstæller[879:222437] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Pengeskabstæller.ViewController Knap:]: unrecognized selector sent to instance 0x13fe0aac0'
*** First throw call stack:
(0x1858641c0 0x18429c55c 0x18586b278 0x185868278 0x18576259c 0x18b6e19a0 0x18b6e1920 0x18b6cbdd0 0x18b6e120c 0x18b6e0d34 0x18b6dbf7c 0x18b6aca44 0x18be99ea8 0x18be93910 0x185812278 0x185811bc0 0x18580f7c0 0x18573e048 0x1871c1198 0x18b717818 0x18b712550 0x1000e9368 0x1847205b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Answer Source

Replace this:

@IBAction func Knap(sender: AnyObject)

with this

@IBAction func Knap(_ sender: AnyObject)

Since Swift 3 you need add an underscore before external parameter name if you want it to be omitted. Most probably the reason for your issue is that you had added IBActions before you have migrated to Swift 3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download