Created
October 21, 2011 19:49
-
-
Save jpoz/1304764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "User.h" | |
@implementation User | |
@synthesize name = _name; | |
@synthesize email = _email; | |
@synthesize device_id = _device_id; | |
+ (User*) current_user { | |
NSString *uuid = [[UIDevice currentDevice] uniqueIdentifier]; | |
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:uuid, @"device_id.eql", nil]; | |
NSError *error = nil; | |
NSArray *users = [User findRemoteWithQuery:query cacheResults:YES error:&error]; | |
User *my_user; | |
if ([users count] != 0) { | |
my_user = [users objectAtIndex:0]; | |
} else { | |
my_user = [[User alloc] init]; | |
my_user.device_id = uuid; | |
NSError *user_error; | |
[my_user saveRemote:&user_error cacheResults:YES]; | |
} | |
return my_user; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment