objcio / core-data

Sample code for the objc.io Core Data book
https://www.objc.io/books/core-data
MIT License
770 stars 198 forks source link

Crash on adding new moody after delete #2

Open oldtrafford91 opened 8 years ago

oldtrafford91 commented 8 years ago

Here is scenario: After adding new new mood, I try to delete it and then add new one. It crash at:

public func saveOrRollback() -> Bool {
    do {
        try save()
        return true
    } catch {
        rollback()
        return false
    }
}

I do some debugging by lldb with po $arg1 and it say: Constraint violation

floriankugler commented 8 years ago

@oldtrafford91 Good catch – this happens because of a uniqueness constraint conflict on a Country or Continent entity. Those entities have a uniqueness constraint defined (using the numericISO3166Code attribute. However, this uniqueness constraint should also include the markedForDeletionDate attribute to allow deleted and non-deleted instances of a country/continent to co-exist. I'll push an update to the code, let's see if that fixes it.

floriankugler commented 8 years ago

@oldtrafford91 unfortunately this doesn't behave the way I expected it to... will think a bit more about what's a good solution.