source: branches/CoreData/SapphireFrappliance/MetaData/SapphireMObjects/SapphireMovieTranslation.m @ 573

Revision 573, 1.7 KB checked in by gbooker, 7 years ago (diff)

Some accellerations

Line 
1#import "SapphireMovieTranslation.h"
2#import "CoreDataSupportFunctions.h"
3
4@implementation SapphireMovieTranslation
5
6+ (SapphireMovieTranslation *)movieTranslationWithName:(NSString *)name inContext:(NSManagedObjectContext *)moc
7{
8        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", name];
9        NSArray *array = doFetchRequest(SapphireMovieTranslationName, moc, predicate);
10        if(![array count])
11                return nil;
12       
13        return [array objectAtIndex:0];
14}
15
16+ (SapphireMovieTranslation *)createMovieTranslationWithName:(NSString *)name inContext:(NSManagedObjectContext *)moc
17{
18        SapphireMovieTranslation *ret = [SapphireMovieTranslation movieTranslationWithName:name inContext:moc];
19        if(ret != nil)
20                return ret;
21       
22        ret = [NSEntityDescription insertNewObjectForEntityForName:SapphireMovieTranslationName inManagedObjectContext:moc];
23        ret.name = name;
24       
25        return ret;
26}
27
28
29- (SapphireMoviePoster *)selectedPoster
30{
31        NSArray *allPosters = [self.postersSet allObjects];
32        NSPredicate *indexSearch = [NSPredicate predicateWithFormat:@"index = %d", self.selectedPosterIndexValue];
33        allPosters = [allPosters filteredArrayUsingPredicate:indexSearch];
34        if(![allPosters count])
35                return nil;
36        return [allPosters objectAtIndex:0];
37}
38
39- (NSArray *)orderedPosters
40{
41        NSArray *allPosters = [self.postersSet allObjects];
42        return [allPosters sortedArrayUsingSelector:@selector(compare:)];
43}
44
45- (SapphireMoviePoster *)posterAtIndex:(int)index
46{
47        NSArray *allPosters = [self.postersSet allObjects];
48        NSPredicate *indexSearch = [NSPredicate predicateWithFormat:@"index = %d", index];
49        allPosters = [allPosters filteredArrayUsingPredicate:indexSearch];
50        if(![allPosters count])
51                return nil;
52        return [allPosters objectAtIndex:0];
53}
54
55@end
Note: See TracBrowser for help on using the repository browser.