0
votes

When I created my core data file and after adding this code into done method to save the data I got an error of above stated topic of unable to find a class.

It also showing an error of

Class not found, using default NSManagedObject instead

@IBAction func done()
{
    let hudView = HudView.hudInView(navigationController!.view, animated: true)

    hudView.text = "Tagged"

    let location = NSEntityDescription.insertNewObjectForEntityForName("Location", inManagedObjectContext: managedObjectContext) as! Location

    location.locationDescription = descriptionText

    location.category = categoryName

    location.latitude = coordinate.latitude

    location.longitude = coordinate.longitude

    location.date = date

    location.placemark = placemark

    var error: NSError?

    if !managedObjectContext.save(&error)
    {
        println("Error: \(error)")

        abort()
    }

    afterDelay(0.6) {self.dismissViewControllerAnimated(true, completion: nil)}
}
1
Do you have Location class in your project directory?Karlos
yes i have but location file not a location classshahin ali agharia
i have location class also in project in my project directoryshahin ali agharia
Is it " class Location: NSManagedObject { " something like this?Karlos
Yes same as you said.shahin ali agharia

1 Answers

0
votes

You have to set the class in your xcdatamodeld file. Go to your projectname.xcdatamodeld -> select the Location table and then select the Data model inspector as show in screenshot below and set the class.

enter image description here

Hope this might be helpful.

Make the following changes in your code

 var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
 var context: NSManagedObjectContext = appDel11.managedObjectContext!
 var location = NSEntityDescription.insertNewObjectForEntityForName("Location", inManagedObjectContext: context) as! NSManagedObject