SharedConversation.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // SharedConversation.m
  3. // WildFireChat
  4. //
  5. // Created by Tom Lee on 2020/10/6.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "SharedConversation.h"
  9. /*
  10. @property(nonatomic, assign)int type;
  11. @property(nonatomic, strong)NSString *target;
  12. @property(nonatomic, assign)int line;
  13. @property(nonatomic, strong)NSString *title;
  14. @property(nonatomic, strong)NSString *portraitUrl;
  15. */
  16. @implementation SharedConversation
  17. + (BOOL)supportsSecureCoding {
  18. return YES;
  19. }
  20. - (void)encodeWithCoder:(NSCoder *)coder {
  21. [coder encodeInt:self.type forKey:@"type"];
  22. [coder encodeObject:self.target forKey:@"target"];
  23. [coder encodeInt:self.line forKey:@"line"];
  24. [coder encodeObject:self.title forKey:@"title"];
  25. [coder encodeObject:self.portraitUrl forKey:@"portrait"];
  26. }
  27. - (nullable instancetype)initWithCoder:(NSCoder *)coder {
  28. if (self = [super init]) {
  29. self.type = [coder decodeIntForKey:@"type"];
  30. self.target = [coder decodeObjectForKey:@"target"];
  31. self.line = [coder decodeIntForKey:@"line"];
  32. self.title = [coder decodeObjectForKey:@"title"];
  33. self.portraitUrl = [coder decodeObjectForKey:@"portrait"];
  34. }
  35. return self;
  36. }
  37. - (void)setTitle:(NSString *)title {
  38. if (!title) {
  39. _title = @"";
  40. } else {
  41. _title = title;
  42. }
  43. }
  44. - (void)setPortraitUrl:(NSString *)portraitUrl {
  45. if (!portraitUrl) {
  46. _portraitUrl = @"";
  47. } else {
  48. _portraitUrl = portraitUrl;
  49. }
  50. }
  51. + (instancetype)from:(int)type target:(NSString *)target line:(int)line {
  52. SharedConversation *sc = [[SharedConversation alloc] init];
  53. sc.type = type;
  54. sc.target = target;
  55. sc.line = line;
  56. return sc;
  57. }
  58. @end