| Conforms to | |
| Framework | /System/Library/Frameworks/SyncServices.framework |
| Availability | Available in Mac OS X v10.5 and later. |
| Companion guide | |
| Declared in | ISyncCoreData.h |
| Related sample code |
The NSPersistentStoreCoordinatorSyncing protocol defines callback messages that are sent to a sync handler while a Core Data application syncs. You set a sync handler when you start a sync session using the syncWithClient:inBackground:handler:error: NSPersistentStoreCoordinator method. The callback messages defined in this protocol are sent before and after most phases of a sync session. A sync handler may implement these optional methods to customize the behavior of sync sessions. For example, a sync handler might change records before their pushed to the sync engine or verify changes pulled from the sync engine before they are applied to managed objects.
Read Syncing Core Data Applications in Sync Services Programming Guide for more details on using Core Data sync.
– managedObjectContextsToMonitorWhenSyncingPersistentStoreCoordinator: required method
– managedObjectContextsToReloadAfterSyncingPersistentStoreCoordinator: required method
– persistentStoreCoordinatorShouldStartSyncing: required method
– persistentStoreCoordinator:willPushChangesInSyncSession: required method
– persistentStoreCoordinator:didPushChangesInSyncSession: required method
– persistentStoreCoordinator:willPullChangesInSyncSession: required method
– persistentStoreCoordinator:didPullChangesInSyncSession: required method
– persistentStoreCoordinator:didFinishSyncSession: required method
– persistentStoreCoordinator:didCancelSyncSession:error: required method
– persistentStoreCoordinator:willPushRecord:forManagedObject:inSyncSession: required method
– persistentStoreCoordinator:willDeleteRecordWithIdentifier:inSyncSession: required method
– persistentStoreCoordinator:willApplyChange:toManagedObject:inSyncSession: required method
– persistentStoreCoordinator:didApplyChange:toManagedObject:inSyncSession: required method
– persistentStoreCoordinator:didCommitChanges:inSyncSession: required method
Returns the managed object contexts that the receiver wants to monitor during the next sync session. (required)
- (NSArray *)managedObjectContextsToMonitorWhenSyncingPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
An array containing the managed object contexts to monitor.
The sync session uses this method to determine if pulled changes should be applied. Pulled changes are ignored—not applied to a record—if any of the managed contexts, returned by this method, changed the same record. In this case, the local changes are pushed in the next sync session and the sync engine is responsible for resolving any conflicts.
Conflicts can result if clients are allowed to change managed objects during a sync session or editing is not disabled during syncing. For example, conflicts can result if the user changes a managed object while the sync session is pulling changes to the same managed object. However, implementing this method does not handle all types of conflicts. The user may still modify a managed object after a sync session applies changes and before a sync session finishes. To avoid this, you should either not allow editing during a sync session, or be prepared to merge local changes with pulled changes after a sync session.
Therefore, although this method is optional, not implementing this method increases the risk of conflicts unless you sync synchronously or disable editing when syncing.
ISyncCoreData.hReturns the managed object contexts that should be reloaded after the persistent store coordinator syncs. (required)
- (NSArray *)managedObjectContextsToReloadAfterSyncingPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
An array containing the managed object contexts to reload.
If you do not implement this method, it is your responsibility to reload managed object contexts after a sync.
ISyncCoreData.hInforms the receiver that pulled changes were applied to a specific record during a sync session. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didApplyChange:(ISyncChange *)change toManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The changes that was applied.
The managed object that corresponds to the changes.
The sync session that applied the changes.
ISyncCoreData.hInforms the receiver that a session was cancelled. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didCancelSyncSession:(ISyncSession *)session error:(NSError *)error
The persistent store coordinator being synced.
The sync session that was cancelled.
Describes the error that caused the cancellation.
ISyncCoreData.hInforms the receiver that all applied changes were committed during a sync session. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didCommitChanges:(NSDictionary *)changes inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
A dictionary containing the changes to possibly multiple objects that were applied and committed. The dictionary contains the following keys: NSInsertedObjectsKey, NSUpdatedObjectsKey, and NSDeletedObjectsKey.
The sync session that committed the changes.
Typically, this method is invoked after the persistent store changes are saved and the sync session receives the clientCommittedAcceptedChanges message. This method can be invoked multiple times during a sync session.
ISyncCoreData.hInforms the receiver that a session was finished. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didFinishSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that finished.
ISyncCoreData.hInforms the receiver that changes were pulled from the sync engine. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didPullChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that pulled the changes.
ISyncCoreData.hInforms the receiver that client changes were pushed to the sync engine. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didPushChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that pushed the changes.
ISyncCoreData.hInforms the receiver that pulled changes will be applied to a specific record during a sync session. (required)
- (ISyncChange *)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willApplyChange:(ISyncChange *)change toManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The changes that will be applied. An ISyncChange object can represent a delete record change, as well as an insert and update record change.
The managed object that corresponds to the changes.
The sync session that is applying the changes.
The change to apply. nil if you do not want to apply this change.
Implement this method if you want to modify a change before it is applied.
ISyncCoreData.hInforms the receiver that a specific record will be deleted during the pushing phase of a sync session. (required)
- (BOOL)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willDeleteRecordWithIdentifier:(NSString *)identifier inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The identifier for the record that will be deleted.
The sync session that is pushing records.
YES to delete the record; otherwise, NO.
Implement this method if you want to verify if a record should be deleted before it is deleted.
ISyncCoreData.hInforms the receiver that changes will be pulled from the sync engine. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPullChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that is pulling the changes.
ISyncCoreData.hInforms the receiver that client changes will be pushed to the sync engine. (required)
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPushChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that is pushing the changes.
ISyncCoreData.hInforms the receiver that client changes to a specific record will be pushed to the sync engine. (required)
- (NSDictionary *)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPushRecord:(NSDictionary *)record forManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The record that will be pushed.
The managed object that corresponds to the record.
The sync session that is pushing records.
The record to push. nil if you do not want to push the record.
Implement this method if you want to modify a record before pushing it.
ISyncCoreData.hReturns whether or not the persistent store coordinator should start syncing. (required)
- (BOOL)persistentStoreCoordinatorShouldStartSyncing:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
YES if the persistent store coordinator can start syncing; otherwise, NO.
ISyncCoreData.hLast updated: 2007-07-11