Skip to content

Instantly share code, notes, and snippets.

@jpoz
Created October 21, 2011 19:49
Show Gist options
  • Save jpoz/1304764 to your computer and use it in GitHub Desktop.
Save jpoz/1304764 to your computer and use it in GitHub Desktop.
#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