forked from 2359media/STXDynamicTableView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTXUser.m
More file actions
70 lines (55 loc) · 1.81 KB
/
STXUser.m
File metadata and controls
70 lines (55 loc) · 1.81 KB
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
68
69
70
//
// STXUser.m
// STXDynamicTableViewExample
//
// Created by Jesse Armand on 9/4/14.
// Copyright (c) 2014 2359 Media Pte Ltd. All rights reserved.
//
#import "STXUser.h"
@interface STXUser ()
@property (copy, nonatomic) NSString *userID;
@property (copy, nonatomic) NSString *username;
@property (copy, nonatomic) NSString *fullname;
@property (copy, nonatomic) NSURL *profilePictureURL;
@end
@implementation STXUser
- (instancetype)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
NSArray *errors;
NSDictionary *mappingDictionary = @{ @"id": KZProperty(userID),
@"username": KZProperty(username),
@"full_name": KZProperty(fullname),
@"profile_picture": KZBox(URL, profilePictureURL) };
[KZPropertyMapper mapValuesFrom:dictionary toInstance:self usingMapping:mappingDictionary errors:&errors];
}
return self;
}
- (NSUInteger)hash
{
return [_userID hash];
}
- (BOOL)isEqualToUser:(STXUser *)user
{
return [user.userID isEqualToString:_userID];
}
- (BOOL)isEqual:(id)object
{
if (self == object) {
return YES;
}
if (![object isKindOfClass:[STXUser class]]) {
return NO;
}
return [self isEqualToUser:(STXUser *)object];
}
- (NSString *)description
{
NSDictionary *dictionary = @{ @"userID": self.userID ? : @"",
@"username": self.username ? : @"",
@"fullname": self.fullname ? : @"",
@"profilePictureURL": self.profilePictureURL ? : @"" };
return [NSString stringWithFormat:@"<%@: %p> %@", NSStringFromClass([self class]), self, dictionary];
}
@end