Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Split Generated FetchRequests Into Multiple Functions. #223

Open
wants to merge 1 commit into from

1 participant

@pbtura

Modified the generation templates to split the generated fetchRequests methods. Each fetch request method now consists of two methods. The first builds and return the NSFetchRequest object. The second executes the fetch request and return the result. This change make it possible for the user to override the fetch request generation in the 'human' version of the class.

pbuchheit Modified the generation templates to split the generated fetchRequest…
… methods. Each fetch request method now consists of two methods. The first builds and return the NSFetchRequest object. The second executes the fetch request and return the result. This change make it possible for the user to override the fetch request generation in the 'human' version of the class.
7ab7f2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2014
  1. Modified the generation templates to split the generated fetchRequest…

    pbuchheit authored
    … methods. Each fetch request method now consists of two methods. The first builds and return the NSFetchRequest object. The second executes the fetch request and return the result. This change make it possible for the user to override the fetch request generation in the 'human' version of the class.
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 28 deletions.
  1. +1 −0  templates/machine.h.motemplate
  2. +20 −28 templates/machine.m.motemplate
View
1  templates/machine.h.motemplate
@@ -93,6 +93,7 @@ extern const struct <$managedObjectClassName$>UserInfo {<$foreach UserInfo userI
<$endif$>
<$endforeach do$>
<$foreach FetchRequest prettyFetchRequests do$>
++ (NSFetchRequest *)requestFor<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>;
<$if FetchRequest.singleResult$>
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>;
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>error:(NSError**)error_;
View
48 templates/machine.m.motemplate
@@ -114,6 +114,23 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
<$endforeach do$>
<$foreach FetchRequest prettyFetchRequests do$>
++ (NSFetchRequest *)requestFor<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>
+{
+ NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel];
+ <$if FetchRequest.hasBindings$>
+ NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys:
+ <$foreach Binding FetchRequest.bindings do2$>
+ <$Binding.name$>_, @"<$Binding.name$>",
+ <$endforeach do2$>
+ nil];
+ <$else$>
+ NSDictionary *substitutionVariables = [NSDictionary dictionary];
+ <$endif$>
+ NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>"
+ substitutionVariables:substitutionVariables];
+ NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\".");
+ return fetchRequest;
+}
<$if FetchRequest.singleResult$>
+ (id)fetch<$FetchRequest.name.initialCapitalString$>:(NSManagedObjectContext*)moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:(<$Binding.type$>)<$Binding.name$>_ <$endforeach do2$>{
NSError *error = nil;
@@ -131,19 +148,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
NSParameterAssert(moc_);
NSError *error = nil;
- NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel];
- <$if FetchRequest.hasBindings$>
- NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys:
- <$foreach Binding FetchRequest.bindings do2$>
- <$Binding.name$>_, @"<$Binding.name$>",
- <$endforeach do2$>
- nil];
- <$else$>
- NSDictionary *substitutionVariables = [NSDictionary dictionary];
- <$endif$>
- NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>"
- substitutionVariables:substitutionVariables];
- NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\".");
+ NSFetchRequest *fetchRequest = [self requestFor<$FetchRequest.name.initialCapitalString$>:moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:<$Binding.name$>_ <$endforeach do2$>];
id result = nil;
NSArray *results = [moc_ executeFetchRequest:fetchRequest error:&error];
@@ -157,9 +162,8 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
result = [results objectAtIndex:0];
break;
default:
- NSLog(@"WARN fetch request <$FetchRequest.name$>: 0 or 1 objects expected, %lu found (substitutionVariables:%@, results:%@)",
+ NSLog(@"WARN fetch request <$FetchRequest.name$>: 0 or 1 objects expected, %lu found ( results:%@)",
(unsigned long)[results count],
- substitutionVariables,
results);
}
}
@@ -184,19 +188,7 @@ const struct <$managedObjectClassName$>UserInfo <$managedObjectClassName$>UserIn
NSParameterAssert(moc_);
NSError *error = nil;
- NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel];
- <$if FetchRequest.hasBindings$>
- NSDictionary *substitutionVariables = [NSDictionary dictionaryWithObjectsAndKeys:
- <$foreach Binding FetchRequest.bindings do2$>
- <$Binding.name$>_, @"<$Binding.name$>",
- <$endforeach do2$>
- nil];
- <$else$>
- NSDictionary *substitutionVariables = [NSDictionary dictionary];
- <$endif$>
- NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"<$FetchRequest.name$>"
- substitutionVariables:substitutionVariables];
- NSAssert(fetchRequest, @"Can't find fetch request named \"<$FetchRequest.name$>\".");
+ NSFetchRequest *fetchRequest = [self requestFor<$FetchRequest.name.initialCapitalString$>:moc_ <$foreach Binding FetchRequest.bindings do2$><$Binding.name$>:<$Binding.name$>_ <$endforeach do2$>];
NSArray *result = [moc_ executeFetchRequest:fetchRequest error:&error];
if (error_) *error_ = error;
Something went wrong with that request. Please try again.