Notifications on save data #134

Closed
opened 2025-12-29 18:23:25 +01:00 by adam · 2 comments
Owner

Originally created by @mrichtsfeld on GitHub (Apr 29, 2017).

Hi John,

First of all, great library. Thanks for that great work.

I have an question regarding save notifications (NSManagedObjectContextDidSaveNotification).

I would need to collect all data after saving and store it on my server. I would normally use the notification mentioned above and get the changed objects via NSDeletedObjectsKey, NSInsertedObjectsKey, NSUpdatedObjectsKey.

Is there any such thing available in your library. I have only found the other way arround, the import. But no export so far. Did I miss it?

Maybe the commitAndWait() can allow a callback which provides this information? Like

.commitAndWait( { (deleted, inserted, updated) => Void in
    // do my sync/data collect stuff here
})

Thanks for your answer. If you need any help regarding the implementation just let me know.

Originally created by @mrichtsfeld on GitHub (Apr 29, 2017). Hi John, First of all, great library. Thanks for that great work. I have an question regarding save notifications (NSManagedObjectContextDidSaveNotification). I would need to collect all data after saving and store it on my server. I would normally use the notification mentioned above and get the changed objects via NSDeletedObjectsKey, NSInsertedObjectsKey, NSUpdatedObjectsKey. Is there any such thing available in your library. I have only found the other way arround, the import. But no export so far. Did I miss it? Maybe the commitAndWait() can allow a callback which provides this information? Like .commitAndWait( { (deleted, inserted, updated) => Void in // do my sync/data collect stuff here }) Thanks for your answer. If you need any help regarding the implementation just let me know.
adam added the question label 2025-12-29 18:23:25 +01:00
adam closed this issue 2025-12-29 18:23:26 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Apr 29, 2017):

You can extract these info from the transaction themselves. Check the BaseDataTransaction methods here: https://github.com/JohnEstropia/CoreStore/blob/develop/Sources/Transactions/BaseDataTransaction.swift#L219
You can pass these objects/objectIDs to your commit completion handler and pass them to *.fetchExisting(...).

CoreStore.beginAsynchronous { (transaction) in
    // ...
    let insertedObjects = transaction.insertedObjects()
    transaction.commit { (result) in
        // ...
        let insertedObjects = CoreStore.fetchExisting(insertedObjects)
        // ...
    }
}
@JohnEstropia commented on GitHub (Apr 29, 2017): You can extract these info from the transaction themselves. Check the `BaseDataTransaction` methods here: https://github.com/JohnEstropia/CoreStore/blob/develop/Sources/Transactions/BaseDataTransaction.swift#L219 You can pass these objects/objectIDs to your commit completion handler and pass them to `*.fetchExisting(...)`. ```swift CoreStore.beginAsynchronous { (transaction) in // ... let insertedObjects = transaction.insertedObjects() transaction.commit { (result) in // ... let insertedObjects = CoreStore.fetchExisting(insertedObjects) // ... } } ```
Author
Owner

@mrichtsfeld commented on GitHub (Apr 29, 2017):

That was exactly what I was looking for. Thanks for pointing me to the right methods.

@mrichtsfeld commented on GitHub (Apr 29, 2017): That was exactly what I was looking for. Thanks for pointing me to the right methods.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore-JohnEstropia#134