当我创建核心数据文件并将此代码添加到完成方法中以保存数据后,我收到了上述主题的错误,即无法找到类。
它还显示错误
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)}
}
最佳答案
您必须在 xcdatamodeld 文件中设置该类。 转到您的项目名称.xcdatamodeld -> 选择位置表,然后选择数据模型检查器(如下面的屏幕截图所示)并设置类。
希望这会有所帮助。
在代码中进行以下更改
var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
var context: NSManagedObjectContext = appDel11.managedObjectContext!
var location = NSEntityDescription.insertNewObjectForEntityForName("Location", inManagedObjectContext: context) as! NSManagedObject
关于ios - 无法为实体 'MyLocations.Location' 加载名为 'Location' 的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043469/