Could you please elaborate on how to it?
It’s very much like the producer/consumer setup, except with the whole database (-:
Imagine that you app wants to publish a database that your appex accesses read-only. You might do something like this:
-
Start with the database in a shared app group container. The appex reads that.
-
When the app has an update, it copies the database to a temporary location. You can use an APFS clone if you want, but a vanilla copy is fine because only the app modifies the file and there can only be one instance of the app running.
-
And the app modifies that copy of the database.
-
When it’s done, it uses rename
to atomically replace the file in the shared container.
-
When the appex reads the file, it’ll either see the old or the new contents.
If the appex needs ongoing access to the database, you can have it open the file. The content access via that file descriptor will always be consistent, because the app never modifies that file. Before using the file descriptor, the appex calls fstat
on the file descriptor and stat
on the file. If the inode numbers match it has the latest. If not, it needs to close and re-open.
Or have the app post a Darwin notification that the appex listens for and refreshes.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"