1

I'm learning Core Data and I have problem. I tried many things but xcode always tell me:

2015-04-25 21:20:44.057 CoreData2[8979:202376] CoreData: warning: Unable to load class named 'Contacts' for entity 'Contacts'. Class not found, using default NSManagedObject instead.

This is my method which I call from viewDidLoad:

func saveData () {

    // delegate
    let delegate = UIApplication.sharedApplication().delegate as! AppDelegate

    // managed object context
    let managedObjectContext = delegate.managedObjectContext

    // entity description
    let entityDescription = NSEntityDescription.entityForName("Contacts", inManagedObjectContext: managedObjectContext!)

    // instance
    let contact = Contacts(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext!)

    //
    contact.name = "Adam"
    contact.adress = "Brno"
    contact.phone = "123456789"

    //

    var error:NSError?
    managedObjectContext?.save(nil)

    if let err = error {

        println("error")

    }

}

my .xcdatamodeld

My Contacts.swift file:

class Contacts: NSManagedObject {

@NSManaged var name: String
@NSManaged var adress: String
@NSManaged var phone: String }

Does anybody know what Im doing wrong? Thank you!

Lachtan
  • 3,793
  • 6
  • 18
  • 28
  • 1
    Can you delete your build files? Sometimes this error might be related to old xcmodel and other related core data files. If you delete your build files and this problem does not be removed. You should change your entity class name field by adding CoreData2 name. Like this, CoreData2.Contacts – burakim Apr 25 '15 at 19:39
  • 1
    Thank you very much! After few attempts it finally works! I deleted build files and renamed class in my xcdatamodel as you adviced. Thanks again man – Lachtan Apr 26 '15 at 12:52

0 Answers0