Skip to content
Newer
Older
100644 58 lines (48 sloc) 1.44 KB
b67af26 @nicolascormier bug fixes + new stuff
authored
1 //
2 // ZTComment.m
3 // zootoolapp
4 //
5 // Created by nico on 26/10/10.
6 // Copyright 2010 Nicolas CORMIER. All rights reserved.
7 //
8
9 #import "ZTComment.h"
10 #import "ZTUser.h"
11
12
13 @implementation ZTComment
14
15 @synthesize user, text, added;
16
17 - (void) dealloc
18 {
19 self.user = nil;
20 self.text = nil;
21 self.added = nil;
22 [super dealloc];
23 }
24
25 - (id) initWithDictionary:(NSDictionary*)dict
26 {
27 if (self = [super init])
28 {
29 NSNumberFormatter* formatter = [[[NSNumberFormatter alloc] init] autorelease];
30 [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
31 id userDic = [dict objectForKey:@"user"];
32 if (userDic && [userDic isKindOfClass:[NSDictionary class]])
33 {
34 self.user = [[[ZTUser alloc] initWithDictionary:userDic] autorelease];
35 }
36 self.text = [[dict objectForKey:@"text"] description];
37 double unixTimestamp = [[formatter numberFromString:[[dict objectForKey:@"added"] description]] doubleValue];
38 self.added = [NSDate dateWithTimeIntervalSince1970:unixTimestamp];
39 }
40 return self;
41 }
42
43 - (NSDictionary*) dictionary
44 {
45 NSMutableDictionary* ret = [NSMutableDictionary dictionary];
46 if (self.user) [ret setObject:[self.user dictionary] forKey:@"user"];
47 if (self.text) [ret setObject:self.text forKey:@"text"];
48 if (self.added) [ret setObject:[NSString stringWithFormat:@"%d", [self.added timeIntervalSince1970]] forKey:@"added"];
49 return ret;
50 }
51
52 - (NSString*) description
53 {
54 return [[self dictionary] description];
55 }
56
57 @end
Something went wrong with that request. Please try again.