-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUser.m
56 lines (43 loc) · 1.48 KB
/
GUser.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
//
// GUser.m
// TwitterTimeline
//
// Created by Joan Barrull Ribalta on 25/08/14.
// Copyright (c) 2014 com.giria. All rights reserved.
//
#import "GUser.h"
#import "GTweet.h"
@implementation GUser
@dynamic identifier;
@dynamic text;
@dynamic name;
@dynamic screenName;
@dynamic imageLink;
@dynamic tweets;
@dynamic retweets;
+ (NSFetchRequest *)fetchRequestForTwitterUserWithIdentifier:(NSNumber *)identifier
{
static dispatch_once_t onceToken;
static NSPredicate *predicateTemplate;
dispatch_once(&onceToken, ^{
predicateTemplate = [NSPredicate predicateWithFormat:@"identifier == $IDENTIFIER"];
});
NSPredicate *predicate = [predicateTemplate predicateWithSubstitutionVariables:
[NSDictionary dictionaryWithObject:identifier forKey:@"IDENTIFIER"]];
NSFetchRequest *fetchRequest = [self fetchRequest];
[fetchRequest setPredicate:predicate];
return fetchRequest;
}
+ (id)twitterUserWithIdentifier:(NSNumber *)identifier inManagedObjectContext:(NSManagedObjectContext *)context
{
NSFetchRequest *fetchRequest = [self fetchRequestForTwitterUserWithIdentifier:identifier];
return [[context executeFetchRequest:fetchRequest error:NULL] lastObject];
}
- (void)importValuesFromDictionary:(NSDictionary *)dictionary
{
self.identifier = dictionary[@"id"];
self.name = dictionary[@"name"];
self.screenName = dictionary[@"screen_name"];
self.imageLink = dictionary[@"profile_image_url"];
}
@end