Search code examples
iosswiftcore-datansmanagedobjectcontext

TableViewCell - Gather ManagedObject


my question is regarding a specific "problem" where I am struggling since hours.

I am having a custom cell (ViewController is ToDoCellVC) in TableViewController "ToDoVC" filled with 2 elements "Title" and "Date".

When I select the cell and delete it -> its working.

But I am also having two buttons inside each cell who should perform 2 actions:

  • Information Button : Display Alert by fetching data from Cell including the Name inside the ManagedObject (Entity: ToDoItems; which is not displayed) and then with the name doing a predicate for another entity (which is working already)

  • Add to other TVC and delete from current TVC : This action should delete the actual data from ToDoVC and move it to DoneVC which has another entity "DoneRecords" with the same attributes.

I think I could accomplish the code by myself if I found a method to gather information about current cell using NSManagedObjectContext.


Solution

  • Rather than having 2 separate entities for your ToDoList, I would have one entity with an isDone Boolean attribute.

    • Cells on your ToDoTVC would display objects where isDone is false

    and

    • Cells on your DoneTVC would display objects where isDone is true.

    When you create your ToDoListItem, set its initial value to false.

    Here's a post on using NSPredicates you'll find helpful for populating your TableViewControllers.

    NSPredicate - filtering values based on a BOOLEAN stored value