Bram
Bram

Reputation: 119

CoreData - Populate tableview with NSManagedObjects but save only one

I'm busy creating an iOS app in Swift 3 for iOS 8+ with CoreData.

I've a tableview with tasks. The tasks are retrieved from an API and each task from the JSON is inserted in a new NSManagedObject "Task". All these "Task" NSManagedObjects are stored in an array so that I have an array with all the "Task" objects from the JSON. Then I populate the tableview with that array of "Task" NSManagedObjects. But, when a user taps on a row, that single "Task" object have to be saved in CoreData (in the "Task" entity).

How can I populate the tableview with "Task" NSManagedObjects without saving all the tasks but only the one that the user taps?

Can anybody point me in the right direction?

Upvotes: 0

Views: 144

Answers (1)

vadian
vadian

Reputation: 285270

You could use an intermediate custom struct.

  • Parse the JSON into a custom struct.
  • Use this struct as model for the table view.
  • When the user taps a row map the struct instance to NSManagedObject and save it.

Upvotes: 1

Related Questions