0

I've the following code which is for editing my contact, but somehow I'm receiving this error: NSString is not a subclass of category. This is my code

func editContact() {
        let index = pickerView.selectedRowInComponent(0)
        let fetchedObject = self.fetchedResultsController_cat.objectAtIndexPath(NSIndexPath(forRow: index, inSection: 0)) as! Category

        contact?.name = nameField.text
        contact?.phone = phoneField.text
        contact?.email = emailField.text
        contact?.photo = UIImageJPEGRepresentation(imageHolder.image, 1)
        contact?.category = categoryField.text
        context?.save(nil)
        var alert = UIAlertController(title: "Notification", message: "Contact edited", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }

It's crashing on this line : contact?.category = categoryField.text Any help ?

  • 1
    This looks like the identical problem as in your previous question http://stackoverflow.com/questions/32812061/coredata-relationship-issue. As explained in the answers, you must assign an instance of `Category` to `contact?.category` not a *string*. – Martin R Sep 28 '15 at 08:26
  • it's different now, I can save to the database, but when I try to edit an existing contact and save new data from the textfield than I got that error. – congolese developper Sep 28 '15 at 08:29
  • It is exactly the same problem. – Martin R Sep 28 '15 at 08:30
  • what I'm trying to achieve now is when i click on a row all the data will be displayed on those fields, I can get them except the category one – congolese developper Sep 28 '15 at 08:36

0 Answers0