André Henrique
André Henrique

Reputation: 167

CoreData ContextObjectsDidChangeNotification called from another thread

Recently while investigating some weird UI behavior of UIPickerView, I reached the conclusion that is was because I was reloading its components in a selector that was called observing the NSManagedObjectContextObjectsDidChangeNotification. The thing is, At least I was pretty sure this will be always be called from the main thread. But I was wrong. I'm using UIManagedDocument, and sometimes I get the following notification from another thread:

NSConcreteNotification 0x14a2664b0 {name = NSObjectsChangedInManagingContextNotification; object = <NSManagedObjectContext: 0x14a3e1be0>; userInfo = {
invalidatedAll =     (
    "0xd00000000d5c000e <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/AdditionalAssetAttributes/p855>",
    "0xd00000000d58000e <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/AdditionalAssetAttributes/p854>",
    "0xd00000000d5c000c <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/Asset/p855>",
    "0xd00000000d58000c <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/Asset/p854>",
    "0xd000000001d40018 <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/SidecarFile/p117>",
    "0xd000000001d00018 <x-coredata://B12EF0BD-E372-44D2-AF2F-8E28C5EF3E00/SidecarFile/p116>"
);
managedObjectContext = "<NSManagedObjectContext: 0x14a3e1be0>";

My question is: Does anyone knows why this notification is being called? What is the purpose of the invalidateAll elements. Also I have no Idea what AdditionalAssetAttributes or SidecarFile are.

Thanks!

Upvotes: 0

Views: 337

Answers (1)

zeroimpl
zeroimpl

Reputation: 2846

I'm seeing this notification as well regularly as of iOS 11. There's not much documentation, but it seems if the notification's userInfo contains the key NSInvalidatedAllObjectsKey (invalidatedAll), then you must refetch all NSManagedObject's from the document that your application has references too. Failure to do see leaves them all no longer usable. The contents of the array can be ignored (e.g. I often find it is empty)

Upvotes: 1

Related Questions