Database Reference
In-Depth Information
The -saveAction: is similar to a save in any Core Data application. There are a
couple of changes that we made just for protection. Before we attempt a save
call, we first check to see whether there are any changes to save. In addition,
instead of handing off the error (if there is one) to the NSApplication to present
via the UI, we instead log the error to the console via a call to -logError: . By
logging the error, we can see all the issues in a more programmer-friendly
setup.
DistributedCDServer/AppDelegate.m
- ( void )logError:(NSError*)error
{
id sub = [[error userInfo] valueForKey:@ "NSUnderlyingException" ];
if (!sub) {
sub = [[error userInfo] valueForKey:NSUnderlyingErrorKey];
}
if (!sub) {
NSLog(@ "%@:%s Error Received: %@" , [self class], __PRETTY_FUNCTION__,
[error localizedDescription]);
return ;
}
if ([sub isKindOfClass:[NSArray class]] ||
[sub isKindOfClass:[NSSet class]]) {
for (NSError *subError in sub) {
NSLog(@ "%@:%s SubError: %@" , [self class], __PRETTY_FUNCTION__,
[subError localizedDescription]);
}
} else {
NSLog(@ "%@:%s exception %@" , [self class], __PRETTY_FUNCTION__,
[sub description]);
}
}
The -logError: attempts to extract the NSUnderlyingException from the userInfo of the
passed-in NSError . If something goes wrong within Core Data that is not part
of the normal failure path, it is possible to get information about the failure
via the stored NSUnderlyingException . If there is no NSUnderlyingException , we look for
a value stored under the key NSUnderlyingErrorKey . If we get something back from
that key, we check to see whether it is a collection, which would indicate
multiple validation errors and print the -localizedDescription to the console. If we
cannot locate either an NSUnderlyingException or an NSUnderlyingErrorKey , we dump
the -localizedDescription for the NSError that is passed in.
Once the Bonjour service has started and the save thread has begun, the
server waits for requests from clients. In a distributed object application, the
server does not get notified when a client connects; it simply starts getting
calls to the exposed methods.
 
 
 
Search WWH ::




Custom Search