Sto provando a spostare un po 'di codice RubyMotion su Swift. Finora funziona. Quello che non capisco è il motivo per cui il seguente risultato non può essere colato per la classe documento:Perché insertNewObjectForEntityForName restituisce solo NSManagedObject?
var newObject : NSManagedObject
NSEntityDescription.insertNewObjectForEntityForName("Document", inManagedObjectContext:context)
as NSManagedObject
La chiamata insertNewObjectForEntityForName restituisce un oggetto di tipo NSManagedObject. Ma perché non inserire NewObjectForEntityForName restituisce un oggetto di tipo Documento come specificato da entity.managedObjectClassName?
mio entità simile a questa:
func DocumentEntity() -> NSEntityDescription {
var entity = NSEntityDescription()
entity.name = "Document"
entity.managedObjectClassName = "Document"
var property = NSAttributeDescription()
property.name = "title"
property.attributeType = NSAttributeType.StringAttributeType
property.optional = false
entity.properties = [property]
return entity
}
class Document : NSManagedObject {
@NSManaged var title : String
}
model = NSManagedObjectModel()
model.entities = [DocumentEntity()]
var store = NSPersistentStoreCoordinator(managedObjectModel: model)
come? NSManagedObject restituisce l'oggetto ma come? Documento restituito n. – rogergl
stessa cosa mi succede con alcune classi di Core Data. – Jigzat