terminating with uncaught exception of type NSException in Swift

824 views Asked by At

I am pretty new to swift and was just playing around with the following tutorial to learn Core Data Basics.

CoreData Tutorial

I've tried to narrow down where the exception is being thrown using breaks. I believe it is when I am trying to pass data through a view controller.

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "Update" {

       // var selectedItem: NSManagedObject = myList[self.tableView.indexp] as NSManagedObject

        let IVC: CreateRiderViewController = (segue.destinationViewController as? CreateRiderViewController)!

        var indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
        var selectedItem: NSManagedObject = myList[indexPath.row] as! NSManagedObject

        IVC.firstName = (selectedItem.valueForKey("firstName") as?String)!
        IVC.lastName = (selectedItem.valueForKey("lastName") as! String?)!
        IVC.phoneNumber = (selectedItem.valueForKey("phoneNumber") as! String?)!
        IVC.eMail = (selectedItem.valueForKey("eMail") as! String?)!
        IVC.exitingItem = selectedItem


    }
}

The view controller I'm attempting to pass this data too looks like this.

class CreateRiderViewController: UIViewController {

@IBOutlet weak var firstNameField: UITextField!
@IBOutlet weak var lastNameField: UITextField!
@IBOutlet weak var phoneNumberField: UITextField!
@IBOutlet weak var eMailField: UITextField!

var exitingItem: NSManagedObject!
var firstName: String = ""
var lastName: String = " "
var phoneNumber: String = " "
var eMail: String = " "



override func viewDidLoad() {
    super.viewDidLoad()

    if (exitingItem != nil) {
        firstNameField.text = firstName
        lastNameField.text = lastName
        phoneNumberField.text = phoneNumber
        eMailField.text = eMail
    }

    // Do any additional setup after loading the view.
}

It should set the text fields text to the row selected from my first view controller. However when i select a row the program seems to crash at the point it is transitioning view controllers.

The error I am getting is

2015-06-09 15:53:51.193 ARRR[37189:4601772] -[UITextInputTraits length]: unrecognized selector sent to instance 0x7fc129f60800
2015-06-09 15:53:51.198 ARRR[37189:4601772] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[UITextInputTraits length]: unrecognized selector sent to instance 0x7fc129f60800'

I believe I am unwrapping something at the wrong time but can not figure it out.

I'm also trying to become better at sharing information to get help trouble shooting and would appreciate feedback on how I can explain my problems more clearly and know if I'm including the right pieces of code / error messages to find the problem.

1

There are 1 answers

0
baselsader On

Check that your UITextField is connected to your ViewController. ctrl-click on all UITextFields in the storyboard and check for broken links (you might have created an outlet in the code but changed its name). Also check that all outlets in the ViewController are connected (a circle appears to the left of the initialisation line, if it's filled it's connected, if it's an empty circle there's a broken link)

Screenshot