title: Reducing code duplication with methods that use NSPredicate
body: <p>I have these two class methods, each one with it's predicate. They're function is to hold information that is going to be displayed in a mapKit and in a UITable View. But I see repeated code, except for the predicate; my question is: how can I avoid these repetitions? </p>
  
  <pre><code>+ (NSArray*)spotType:(NSString*)type{
      NSPersistentContainer *persistenceContainer = [AppDelegate sharedDelegate].persistentContainer;
      NSPredicate* predicate = [NSPredicate predicateWithFormat:@"type =%@", type];
      NSManagedObjectContext *context = persistenceContainer.viewContext;
      NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Spot"];
      [request setPredicate:predicate];
      NSError *error;
      NSArray *result = [context executeFetchRequest:request error:&amp;error];
      if (error != nil) {
          NSLog(@"[Spot spotType] -&gt; %@", [error localizedDescription]);
          return nil;
      }
      return result;
  }
  
  + (NSArray*)spotWithType:(NSString*)type{
      NSPersistentContainer *persistenceContainer = [AppDelegate sharedDelegate].persistentContainer;
      NSPredicate* predicate = [NSPredicate predicateWithFormat:@"NOT (type = %@)", type];
      NSManagedObjectContext *context = persistenceContainer.viewContext;
      NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Spot"];
      [request setPredicate:predicate];
      NSError *error;
      NSArray *result = [context executeFetchRequest:request error:&amp;error];
      if (error != nil) {
          NSLog(@"[Spot spotWithType] -&gt; %@", [error localizedDescription]);
          return nil;
      }
      return result;
  }
  </code></pre>