-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.m
60 lines (47 loc) · 1.22 KB
/
User.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
//
// User.m
// unnamed
//
// Created by Bruce Ng on 2/17/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//
#import "User.h"
NSString * const PFObjectName = @"User";
NSString * const UserDidLogoutNotification = @"UserDidLogoutNotification";
@interface User ()
@end
@implementation User
static User * _currentUser = nil;
+ (User *)currentUser {
if (_currentUser == nil) {
PFUser *user = [PFUser currentUser];
_currentUser = [[User alloc] initWithPFUser:user];
}
return _currentUser;
}
+ (void)setCurrentUser:(User *)user {
if (user == nil) {
[PFUser logOut];
_currentUser = nil;
} else {
_currentUser = user;
}
}
+ (void)logout {
[User setCurrentUser:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidLogoutNotification object:nil];
}
- (id)initWithPFUser:(PFUser *)user {
self = [super init];
if (self) {
self.parseUser = user;
NSDictionary *profile = user[@"profile"];
self.name = profile[@"name"];
self.profileImageUrl = profile[@"pictureURL"];
}
return self;
}
- (BOOL)isEqualUser:(User *)user {
return [self.parseUser.objectId isEqualToString:user.parseUser.objectId];
}
@end