DavidK
DavidK

Reputation: 319

“Unrecognized selector sent to instance” swift

I keep getting a “Unrecognized selector sent to instance” in the addButtonDidTouch function when ever I press the button. I have no idea what I might be doing wrong.

@IBAction func addButtonDidTouch(_ sender: AnyObject) {
    let alert = UIAlertController(title: "Grocery Item",
                                  message: "Add an item to the list",
                                  preferredStyle: .alert)

    let saveAction = UIAlertAction(title: "Save",
                                   style: .default) { action in
       guard let textField = alert.textFields?.first,
        let text = textField.text else { return }

        let listItem = ListItem(name: text, addedByUser: self.user.email, completed: false)

        let listItemRef = self.ref.child(text.lowercased())

        listItemRef.setValue(listItem.toAnyObject())
    }

the whole error im getting is

[UITableViewController addButtonDidTouch:]: unrecognized selector sent to instance 0x7fba30612ce0

Upvotes: 1

Views: 2311

Answers (2)

Benoit Canonne
Benoit Canonne

Reputation: 455

If you have crash with external framework, Add -Objc in Targets -> Build Settings -> Linking -> Other Linker Flags

Upvotes: -1

Graham Perks
Graham Perks

Reputation: 23398

In your storyboard you have not set the class of this UITableViewController subclass. In IB, select the view controller, then visit the third tab over in the inspector. You need to set the Class to be your class.

I can tell because the error refers to UITableViewController not your custom subclass.

Upvotes: 1

Related Questions