Database Reference
In-Depth Information
To show and test KVO across the distributed objects, we loop over the NSMan-
agedObject objects within the NSArray and update their name to a globally unique
string that we retrieve from NSProcessInfo , using a #define to make it a little easier
to read. The #define is as follows:
#define GUID [[NSProcessInfo processInfo] globallyUniqueString]
-testObjectInsertion Implementation
Testing object creation is only a single call to the server. However, to test that
we can start using the object immediately, we also set its name using a globally
unique string received from the NSProcessInfo . In addition, we added a random
into this method so that approximately 50 percent of the time it would not
do an insertion. This step adds a bit of randomness to the data testing and
helps keep the number of Test entities on the server low.
DistributedCDClient/AppDelegate.m
- ( void )testObjectInsertion
{
if ((rand() % 2) == NO) return ;
NSManagedObject *object = [server createObject];
[object setValue:GUID forKey:@ "name" ];
}
-testObjectDeletion Implementation
-testObjectDeletion is a fair bit more complicated than -testObjectInsertion because
we need to have a reference to an object first before we can delete it. Therefore,
this method starts off by calling -allObjects on the server to get an NSArray of Test
entities. From that NSArray , we randomly select an entity to delete and call
-deleteObject: on the server.
DistributedCDClient/AppDelegate.m
- ( void )testObjectDeletion
{
NSArray *objects = [server allObjects];
if (![objects count]) return ;
int index = (rand() % [objects count]);
NSManagedObject *toBeDeleted = [objects objectAtIndex:index];
[server deleteObject:toBeDeleted];
}
-testChildInsertion Implementation
Two methods are available to us for testing relationships: child creation and
child deletion. In the first, -testChildInsertion , we start off by getting an NSArray of
 
 
 
Search WWH ::




Custom Search