Anthony DeFallo
Anthony DeFallo

Reputation: 29

Edit UITableViewCell pulling data from CoreData

I'm trying to pull my information from a selected cell from UITableView with

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let resultant = segue.destination as? EditViewController {
        resultant.intention = intentionsArray[(intentionsTable.indexPathForSelectedRow?.row)!]
    }

}

My EditViewController code is

var intention:EIntentions?

I keep getting the error below (EIntentions is my entity, eIntentionCell is my string attribute)

Cannot assign value of type 'NSManagedObject' to type 'EIntentions?'

My array fetching the data from CoreData is

var intentionsArray: [NSManagedObject] = []

I know it is an error with the NSManagedObject array. Essentially, I'm trying to pass the selected cell's text to a text field in EditViewController. I just cannot figure out what I'm doing wrong.

Upvotes: 0

Views: 35

Answers (1)

tereks
tereks

Reputation: 1298

Ok, so you have

var intentionsArray: [NSManagedObject] = []

This is array of NSManagedObject. And EditViewController is expecting EIntentions object.

Either way EIntentions and NSManagedObject are totally different objects, that's why you getting this error. You must init

var intentionsArray: [EIntentions] = []

to make it work like you want. If you've created EIntentions right, then fetching EIntentions objects from database will go smooth and everything will work

Upvotes: 0

Related Questions