Friday, October 1, 2021

iCloudCoreDataStarter and Temporary IDs Bug

Chad Etzel (tweet):

In the course of building Sticker Doodle (which you should go download right now), I ran into many brick walls and learned way too much about Core Data, iCloud sync, Collection and Table Views, and Diffable Data Sources.

There is documentation for each of those individually, but I could find no clear and simple example project that ties them all together in a neat little bow.

Well, that changes today.


Before .save() is called on the managed object context, this temporary ID can be used to fetch the object, refer to it, etc… it acts like a normal NSManagedObjectID -- HOWEVER, after .save() is called on the managed object context, 2 things are supposed to happen:

  1. NSManagedObjects with temporary IDs are supposed to be assigned a permanent ID and those objects updated in memory with the new ID.

  2. The managed object context forgets all temporary IDs and attempting to use them to identify an object will fail.

There seems to be a bug (in iOS 14 and iOS 15 as of my latest testing) where sometimes Step 1 will not actually happen and newly inserted and saved objects will still have a temporary ID!! This has led to all sorts of unexpected and frustrating behavior until I figured out what was actually going on. There are several developer forum posts and Stack Overflow questions regarding the same behavior, so I am not the only one that has experienced this bug.


Comments RSS · Twitter

Leave a Comment