Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Pulling the Truth

Once the mingle is complete, it is time to pull down any changes, deletions, or additions from the truth database. Like the previous push phase, there are two types of pull: a slow pull and a fast pull. During the slow pull, all the objects will be pulled down from the truth database, so all the objects of that data type should be removed from the local store first. During a fast pull, only the changes, additions, and deletions are pulled down; so it is not necessary to remove the local store.

To determine which type of pull will occur for each object, the application needs to ask the session:

entityEnumerator = [filtered objectEnumerator];
NSMutableArray *pullArray = [NSMutableArray array];

while (entityName = [entityEnumerator nextObject]) {
 if (![sess shouldPullChangesForEntityName:entityName]) {
  continue;
 }
 [pullArray addObject:entityName];
 if ([sess shouldReplaceAllRecordsOnClientForEntityName:entityName]) {
  [self deleteAllRecordsForkey:entityName];
 }
}

From the application’s point of view, the primary difference between these two pull types is whether or not to delete the existing data. Therefore, the client application needs to record only whether or not there is any data coming down, not which type of pull it is.

Once I have a list of the entities that need to be pulled, the next step is to request the actual changes from the session and then implement those changes locally:

NSEnumerator *changeEnumerator = [sess changeEnumeratorForEntityNames:pullArray];
ISyncChange *changeItem;
while (changeItem = [changeEnumerator nextObject]) {
 switch ([changeItem type]) {
  case ISyncChangeTypeAdd:
   //process add
   break;
  case ISyncChangeTypeDelete:
   //process delete
   break;
  case ISyncChangeTypeModify:
   //process modify
   break;
 }
}

Processing the actual sync change items is beyond the scope of this article. However because the data is stored as an NSDictionary, it is a fairly trivial task to update a local store.

  • + Share This
  • 🔖 Save To Your Account