JCCEmoticon.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // JCCEmotiocon.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/3/9.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. open class JCCEmoticon: JCEmoticon {
  10. public required init?(object: NSDictionary) {
  11. guard let id = object["id"] as? String, let title = object["title"] as? String, let type = object["type"] as? Int else {
  12. return nil
  13. }
  14. self.id = id
  15. self.title = title
  16. super.init()
  17. self.image = object["image"] as? String
  18. self.preview = object["preview"] as? String
  19. if type == 1 {
  20. self.contents = object["contents"]
  21. }
  22. }
  23. public static func emoticons(with objects: NSArray, at directory: String) -> [JCCEmoticon] {
  24. return objects.flatMap {
  25. guard let dic = $0 as? NSDictionary else {
  26. return nil
  27. }
  28. guard let e = self.init(object: dic) else {
  29. return nil
  30. }
  31. if let name = e.preview {
  32. e.contents = UIImage(contentsOfFile: "\(directory)/\(name)")
  33. }
  34. return e
  35. }
  36. }
  37. var id: String
  38. var title: String
  39. var image: String?
  40. var preview: String?
  41. }