diff options
Diffstat (limited to 'Juick/Model')
-rw-r--r-- | Juick/Model/Attachment.m | 29 | ||||
-rw-r--r-- | Juick/Model/Message.h | 12 | ||||
-rw-r--r-- | Juick/Model/Message.m | 2 | ||||
-rw-r--r-- | Juick/Model/User.h | 1 |
4 files changed, 26 insertions, 18 deletions
diff --git a/Juick/Model/Attachment.m b/Juick/Model/Attachment.m index 006b72e..e0de2ca 100644 --- a/Juick/Model/Attachment.m +++ b/Juick/Model/Attachment.m @@ -11,20 +11,23 @@ @implementation Attachment +(Attachment *) fromJSON:(NSDictionary *)jsonData { - Attachment *attachment = [Attachment new]; - attachment.url = jsonData[@"url"]; - attachment.width = jsonData[@"width"]; - attachment.height = jsonData[@"height"]; - if (jsonData[@"small"]) { - attachment.small = [Attachment fromJSON:jsonData[@"small"]]; + if (jsonData[@"url"]) { + Attachment *attachment = [Attachment new]; + attachment.url = jsonData[@"url"]; + attachment.width = jsonData[@"width"]; + attachment.height = jsonData[@"height"]; + if (jsonData[@"small"]) { + attachment.small = [Attachment fromJSON:jsonData[@"small"]]; + } + if (jsonData[@"medium"]) { + attachment.medium = [Attachment fromJSON:jsonData[@"medium"]]; + } + if (jsonData[@"thumbnail"]) { + attachment.thumbnail = [Attachment fromJSON:jsonData[@"thumbnail"]]; + } + return attachment; } - if (jsonData[@"medium"]) { - attachment.medium = [Attachment fromJSON:jsonData[@"medium"]]; - } - if (jsonData[@"thumbnail"]) { - attachment.thumbnail = [Attachment fromJSON:jsonData[@"thumbnail"]]; - } - return attachment; + return nil; } @end diff --git a/Juick/Model/Message.h b/Juick/Model/Message.h index 33d9911..5c85b1e 100644 --- a/Juick/Model/Message.h +++ b/Juick/Model/Message.h @@ -11,22 +11,26 @@ #import "Attachment.h" #import "Entity.h" +NS_ASSUME_NONNULL_BEGIN + @interface Message : NSObject -@property NSNumber *mid; -@property NSNumber *rid; +@property NSNumber * _Nonnull mid; +@property NSNumber * _Nullable rid; @property User *user; -@property NSString *text; +@property NSString * _Nullable text; @property NSArray<NSString *> *tags; @property NSArray<Entity *> *entities; @property NSString *timestamp; @property NSString *attach; @property NSString *repliesBy; @property NSNumber *repliesCount; -@property Attachment *attachment; +@property Attachment * _Nullable attachment; @property BOOL service; @property BOOL unread; +(Message *) fromJSON:(NSDictionary *)jsonData; @end + +NS_ASSUME_NONNULL_END diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m index d39be54..afc499e 100644 --- a/Juick/Model/Message.m +++ b/Juick/Model/Message.m @@ -13,7 +13,7 @@ + (Message *) fromJSON:(NSDictionary *)jsonData { Message * message = [Message new]; message.mid = jsonData[@"mid"]; - message.rid = jsonData[@"rid"]; + message.rid = [NSNumber numberWithInt:jsonData[@"rid"]]; message.text = jsonData[@"body"]; message.attach = jsonData[@"photo"][@"small"]; message.repliesCount = jsonData[@"replies"]; diff --git a/Juick/Model/User.h b/Juick/Model/User.h index 4bbf332..5941a90 100644 --- a/Juick/Model/User.h +++ b/Juick/Model/User.h @@ -7,6 +7,7 @@ // @import Foundation; +@import UIKit; @interface User : NSObject @property (nonatomic, strong) NSString *uname; |