-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIllustrator+IllustratorModel.m
67 lines (45 loc) · 1.98 KB
/
Illustrator+IllustratorModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// Illustrator+IllustratorModel.m
// Ludow2
//
// Created by Guillaume ESTREM on 30/03/2015.
// Copyright (c) 2015 JACQUEZ_ESTREM. All rights reserved.
//
#import "Illustrator+IllustratorModel.h"
@implementation Illustrator (IllustratorModel)
+(int) addIllustrator:(NSString *) IllustratorName withEntity:(NSEntityDescription *) entityDesc inManagedObjectContext :(NSManagedObjectContext *) context {
Illustrator* anIllustrator=nil;
NSError* error = nil;
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSPredicate* predicat = [NSPredicate predicateWithFormat:@"%K LIKE [c]%@",@"illustratorName",IllustratorName];
[request setPredicate:predicat];
NSArray* result = [context executeFetchRequest:request error:&error];
int res=0;
if(!error){
if([result count]==0){// il faut en créer un
anIllustrator = [[Illustrator alloc] initWithEntity:entityDesc insertIntoManagedObjectContext:context];
anIllustrator.illustratorName=IllustratorName;
res=1;
}
}
return res;
}
+(int) updateIllustrator:(NSString *) IllustratorName withName:(NSString*) newIllustratorName withEntity:(NSEntityDescription *) entityDesc inManagedObjectContext :(NSManagedObjectContext *) context {
Illustrator* anIllustrator=nil;
NSError* error = nil;
NSFetchRequest* request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
//On vérifie qu'il n'y ait pas déjà cette fonction dans la base
NSPredicate* predicat = [NSPredicate predicateWithFormat:@"%K LIKE [c]%@",@"illustratorName",IllustratorName];
[request setPredicate:predicat];
NSArray* result = [context executeFetchRequest:request error:&error];
int res=0;
if(!error){
anIllustrator=result[0];
anIllustrator.illustratorName=newIllustratorName;
res=1;
}
return res;
}
@end