mardi 23 juin 2015

Segue error - failed to call designated initializer on nsmanagedobject class

In tableview controller #1, I initialize an array of NSManagedObjects (entity named "Date") in viewDidLoad. var datesArray = [Date](). I use this array to populate the table data.

When a user selects a cell, I want to pass that selected Date object via the index path to view controller #2, a details view. This is what I have in prepareForSegue for tableview controller #1:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let selectedIndexPath = tableView.indexPathForSelectedRow()
    if segue.identifier == "ShowDateDetails" {
        let dateDetailsVC = segue.destinationViewController as! DateDetailsVC = datesArray[selectedIndexPath!.row] as Date

In view controller #2 I have a simple var date = Date() property.

When I select a row in the table view, it crashes on = datesArray[selectedIndexPath!.row] as Date with the error:

CoreData: error: Failed to call designated initializer on NSManagedObject class 'DateAid.Date'

Can anyone either guide me to a solution, or explain the reasoning behind why it's happening in semi-layman's terms? I'd like to avoid having to perform a fetch request in view controller #2 unless that's not possible. For context, my Core Data skills are 1.5/5 at the moment.

See more ..

Aucun commentaire:

Enregistrer un commentaire