Having a strange issue with Core Data in a Swift app. I'm reasonably well-versed in Core Data but it seems like there are some (new) rough edges and "gotchas" when it comes to using it in Swift.
I can insert new objects into the context just fine, and retrieve them from the same context elsewhere in my app while running. However, whenever I try to save the context, it fails for no apparent reason (managedObjectContext.save() returns false). When I log or inspect the error pointer, it's 0x0000000...so I'm not getting any hints as to what's gone wrong.
func saveContext() {
let error = NSErrorPointer()
if (!self.managedObjectContext.save(error)) {
println("*** Failed to save MOC with error: \(error.debugDescription)")
}
}
I set a breakpoint and inspected the context, partial results below...I also po'd the 'insertedObjects' property and did, indeed, find all the data I was trying to save. Everything looked fine there.
Why won't the context save? I realize that with no error or exception there's not a lot to go off, but I'm hoping someone has encountered this and either knows a fix or at least can point me in the right direction. Thanks :)
I turned on SQL debugging and get the following when I try to save. I'm not a SQL expert by any means but this looks like something's missing. Namely, I don't see any INSERT statements. Also, curiously, this output only gets generated the first time I try to add a bookmark when launching the app. After that, it's mum.
2015-03-23 14:19:13.152 NTBrowser[3535:157990] CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA' 2015-03-23 14:19:13.152 NTBrowser[3535:157990] CoreData: sql: pragma journal_mode=wal 2015-03-23 14:19:13.152 NTBrowser[3535:157990] CoreData: sql: pragma cache_size=200 2015-03-23 14:19:13.153 NTBrowser[3535:157990] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADAT