2

I forgot to check Use Core Data for my project. How can I include Core Data using Swift?

I already added Data Model, CoreData.fraMework,

I got the error message : Use of unresolved identifier 'managedObjectContext'

    let destination = NSEntityDescription.insertNewObjectForEntityForName(
        entityName,
        inManagedObjectContext: managedObjectContext!) as Destination
dandan78
  • 13,328
  • 13
  • 64
  • 78
jilu
  • 125
  • 1
  • 2
  • 9
  • Sounds like you also need to read the manual... both swift and core data manuals. You obviously haven't got 'managedObjectContext' declared in your code. – bandejapaisa Nov 13 '14 at 21:18
  • Sounds like you are right. Thanks for your helpful advice. – jilu Nov 14 '14 at 17:30
  • possible duplicate of [Adding Core Data to existing iPhone project](http://stackoverflow.com/questions/2032818/adding-core-data-to-existing-iphone-project) – 123 Sep 30 '15 at 00:02

1 Answers1

2

The CoreData code is created in your AppDelegate. One way to add the support - that is faster than starting from scratch - is to create a new project of the same type with CoreData and then copy and paste the CoreData related methods and properties from the new AppDelegate to your existing project's AppDelegate. Then you will need to create a new Data Model file. The pasted AppDelegate code will have couple of hard coded things that you will probably have to modify, like the model name and your database name.

MirekE
  • 11,515
  • 5
  • 35
  • 28
  • Good advice. I was almost in the process to start for scratch. Thanks for your help. – jilu Nov 14 '14 at 17:32