我正在使用来自objC的核心数据手册的代码,但在尝试使用以下代码将新对象插入托管对象上下文时遇到了一个奇怪的错误。的NSManagedObjectContext:
/**
Helper method - avoids manual downcast result of an insert action and entity does not have to be referenced by name
- returns: new entity (NSManagedObject)
*/
public func insertObject<A: ManagedObject where A: ManagedObjectType>() -> A {
NSLog("\(A.entityName) - \(self)")
guard let obj = NSEntityDescription.insertNewObjectForEntityForName(A.entityName, inManagedObjectContext: self) as? A else
{ fatalError("Failed to insert entity into context") }
return obj
}
插入失败,并且未实例化对象。检查托管对象上下文(在本例中为self)提供以下调试信息:
Printing description of self:
expression produced error: /var/folders/__/c3n7c0bd35v5f7qxv11gcg280000gn/T/lldb/25862/expr10.swift:1:46: error: use of undeclared type 'CoreData'
$__lldb__DumpForDebugger(Swift.UnsafePointer<CoreData.NSManagedObjectContext>(bitPattern: 0x116b90fa0).memory)
^~~~~~~~
/var/folders/__/c3n7c0bd35v5f7qxv11gcg280000gn/T/lldb/25862/expr10.swift:1:45: note: while parsing this '<' as a type parameter bracket
$__lldb__DumpForDebugger(Swift.UnsafePointer<CoreData.NSManagedObjectContext>(bitPattern: 0x116b90fa0).memory)
有什么想法吗?我是一名核心数据新手,所以我不仅无能为力!