I've been trying to do a simple CoreData task, saving data. I'm sure it works in Beta 6, but errors starting appearing after updating to Beta 7.
I think I have to add '?' or '!' based on the error hint, but just not smart enough to figure out where!
@IBAction func saveItem(sender: AnyObject) {
// Reference to App Delegate
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
// Reference our moc (managed object content)
let contxt: NSManagedObjectContext = appDel.managedObjectContext!
let ent = NSEntityDescription.entityForName("List", inManagedObjectContext: contxt)
// Create instance of our data model and initialize
var newItem = Model(entity: ent, insertIntoManagedObjectContext: contxt)
// Map our attributes
newItem.item = textFieldItem.text
newItem.quanitity = textFieldQuantity.text
newItem.info = textFieldInfo.text
// Save context
contxt.save(nil)
}
The error says
Value of optional type 'NSEntityDescription?' not unwrapped; did you mean to use '!' or '?'
At the line
var newItem = Model(entity: ent, insertIntoManagedObjectContext: contxt)
Everytime I seem to have clear the error and compiles ok, clicking the 'Save' shows in the debug area
fatal error: unexpectedly found nil while unwrapping an Optional value