# Cannot figure out how to pass CoreData through segue

**URL:** <https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714>\
**Category:** Swift\
**Created:** [June 9, 2016, 5:24am UTC](https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714 "2016-06-09T05:24:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thunderken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thunderken/32/78895_2.png) [@thunderken](https://forums.kodeco.com/u/thunderken)\
**Post date:** [June 9, 2016, 5:24am UTC](https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714/1 "2016-06-09T05:24:35Z")

</div>

I am trying to pass data from the table view controller to a details table view controller with core data. I had a local data schema that was working but trying to switch it over and now I cannot compile the app. I get an error stating: `Cannot assign value of type 'SetupEntity' to type '[String:Any Object]'`. The issue seems to be at the end on the seque and passing the data.

I am new to this so I hope I am explaining this right.

if I do `print(toView.setup)` I get `[:]` in the console.  
If i do `print(setups[indexPath.row])` I get this (which is the correct data):

```
<Setups.SetupEntity: 0x7fb4e1d608d0> (entity: SetupEntity; id: 0xd000000000040000 <x-coredata://435FF409-CFE7-4A1C-9312-504C98955F75/SetupEntity/p1> ; data: {
    Title = "Title #7";
    Name = "Your Name";
}

```

- 

```
import UIKit
import CoreData

class SetupsTableTableViewController: UITableViewController {

let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
var setups = [SetupEntity]() //From CoreData

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedRowHeight = 100
    tableView.rowHeight = UITableViewAutomaticDimension

}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    reloadData()
    tableView.reloadData()
}

func reloadData() {
    let fetchRequest = NSFetchRequest(entityName: "SetupEntity")
    
    do {
        if let results = try managedObjectContext.executeFetchRequest(fetchRequest) as? [SetupEntity] {
            setups = results
        }
    } catch {
        fatalError("There was an error fetching the list of setups!")
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return setups.count //From CoreData
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("SetupsCell") as! SetupsTableViewCell
    
    let setup = setups[indexPath.row]
    
    cell.configureWithSetup(setup)
    
    return cell
    
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("DetailsSegue", sender: self)
    
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

// MARK: - Misc

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "DetailsSegue" {
        
        let toView = segue.destinationViewController as! DetailsTableViewController
        let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
        
        //This is where my problem is
         toView.setup = setups[indexPath.row]
        
    }
}

}

```

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [June 11, 2016, 4:00pm UTC](https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714/2 "2016-06-11T16:00:07Z")

</div>

What kind of variable is toview.setup?

---

<div class="post-metadata">

**Author:** ![thunderken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thunderken/32/78895_2.png) [@thunderken](https://forums.kodeco.com/u/thunderken)\
**Post date:** [June 12, 2016, 11:44pm UTC](https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714/3 "2016-06-12T23:44:22Z")

</div>

I was just following a tutorial and trying to pass the data from a tableview to a new controller that has the data from that row in it in and more details.

---

<div class="post-metadata">

**Author:** ![thunderken](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thunderken/32/78895_2.png) [@thunderken](https://forums.kodeco.com/u/thunderken)\
**Post date:** [June 14, 2016, 8:53pm UTC](https://forums.kodeco.com/t/cannot-figure-out-how-to-pass-coredata-through-segue/15714/4 "2016-06-14T20:53:39Z")

</div>

OK so I have the error going away with this updated code, and the `setup` variable seems to be passing info in the console, not it is not appearing in my detailtableview:

```
import UIKit
import CoreData

class SetupsTableTableViewController: UITableViewController {

let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
// var managedObjectContext: NSManagedObjectContext!
var setups = [SetupEntity]() //From CoreData

@IBAction func profileButtonDidTouch(sender: AnyObject) {
    performSegueWithIdentifier("ProfileSegue", sender: self)
}

@IBAction func addSetupButtonDidTouch(sender: AnyObject) {
    performSegueWithIdentifier("AddSetupSegue", sender: self)
}

override func viewDidLoad() {
    
    super.viewDidLoad()

    tableView.estimatedRowHeight = 100
    tableView.rowHeight = UITableViewAutomaticDimension

}

override func viewWillAppear(animated: Bool) {

    super.viewWillAppear(animated)
    reloadData()
    tableView.reloadData()

}

func reloadData() {
    
    let fetchRequest = NSFetchRequest(entityName: "SetupEntity")
    
    do {
        if let results = try managedObjectContext.executeFetchRequest(fetchRequest) as? [SetupEntity] {
            setups = results
        }
    } catch {
        fatalError("There was an error fetching the list of setups!")
    }
}

override func didReceiveMemoryWarning() {

    super.didReceiveMemoryWarning()

}

// MARK: - Table view data source

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return setups.count //From CoreData

}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("SetupsCell") as! SetupsTableViewCell
    let setup = setups[indexPath.row]
    cell.configureWithSetup(setup)

    return cell
    
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    performSegueWithIdentifier("DetailsSegue", sender: self)
    self.tableView.deselectRowAtIndexPath(indexPath, animated: true)

}

// MARK: - Misc

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    
    if segue.identifier == "DetailsSegue" {
// let destinationVC = segue.destinationViewController as! DetailsTableViewController
        let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
        let setup = setups[indexPath.row]
        print(setup)
    }
    
}

}

```
