Database Reference
In-Depth Information
checks against the default and/or create the NSManagedObject , we test the value
to see whether it is an NSNumber or NSDate . If it is, we pass in its -stringValue or
-description as the value for the NSManagedObject . Otherwise, we pass in the value
directly to the NSManagedObject . Once the value is set, we call -didChangeValueForKey:
to complete the KVO notification.
-createParameter:
CDPreferences/DocumentPreferences.m
- (NSManagedObject*)createParameter:(NSString*)name
{
NSManagedObject *param;
NSManagedObjectContext *moc;
moc = [[self associatedDocument] managedObjectContext];
param = [NSEntityDescription insertNewObjectForEntityForName:@ "Parameter"
inManagedObjectContext:moc];
[param setValue:name forKey:@ "name" ];
return param;
}
The -createParameter: method creates a new NSManagedObject and sets the name property
with the passed-in value. It does not set the value property, leaving that up to the
caller. This allows us to set a nil parameter if we really need one.
-allParameters
CDPreferences/DocumentPreferences.m
- (NSDictionary*)allParameters;
{
NSManagedObjectContext *moc;
NSError *error = nil;
moc = [[self associatedDocument] managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@ "Parameter"
inManagedObjectContext:moc]];
NSArray *params = [moc executeFetchRequest:request error:&error];
if (error) {
DLog(@ "Error fetching parameter: %@\n%@" , [error localizedDescription],
[error userInfo]);
return nil;
}
NSMutableDictionary *dict = [[self defaults] mutableCopy];
for (NSManagedObject *param in params) {
NSString *name = [param valueForKey:@ "name" ];
NSString *value = [param valueForKey:@ "value" ];
[dict setValue: value forKey:name];
}
return dict;
}
 
 
 
Search WWH ::




Custom Search