KMAdvertisementModel.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // KMAdvertisementModel.swift
  3. // KMAdvertisement
  4. //
  5. // Created by lizhe on 2022/11/30.
  6. //
  7. //参考链接 https://www.jianshu.com/p/a24cf8f37860
  8. //func encode<T>(of model: T) throws where T: Codable {
  9. // let encoder = JSONEncoder()
  10. // encoder.outputFormatting = .prettyPrinted
  11. // let encodedData = try encoder.encode(model)
  12. // print(String(data: encodedData, encoding: .utf8)!)
  13. //}
  14. //func decode<T>(of jsonString: String, type: T.Type) throws -> T where T: Codable {
  15. // let data = jsonString.data(using: .utf8)!
  16. // let decoder = JSONDecoder()
  17. // let model = try! decoder.decode(T.self, from: data)
  18. // return model
  19. //}
  20. /**
  21. */
  22. public struct KMAdvertisementModel: Codable {
  23. public let appName: KMAdvertisementAppNameType? //产品名
  24. public let platform: KMAdvertisementPlatformType? //平台
  25. public let showType: KMAdvertisementShowType? //显示类型
  26. public let startTime: String? //开始时间 时间戳
  27. public let endTime: String? //结束时间 时间戳
  28. public let subscribeType: KMAdvertisementSubscribeType? //是否订阅
  29. public let version: String? //小于等于此版本生效
  30. let content:[Section]
  31. public struct Section: Codable {
  32. let sectionTitle: Text?
  33. let content: [Content]
  34. public struct Content: Codable {
  35. var index: Int?
  36. let title: Text?
  37. let imageURL: Image?
  38. let ipadImageURL: Image?
  39. let linkURL: Language?
  40. let tips: Language?
  41. let button: Text?
  42. let actionType: KMAdvertisementActionType?
  43. }
  44. }
  45. struct Text: Codable {
  46. let font: Font?
  47. let color: Color?
  48. let background: Background?
  49. let language: Language?
  50. }
  51. struct Font: Codable {
  52. let name: String?
  53. let size: Int?
  54. }
  55. struct Color: Codable {
  56. let height: ColorState?
  57. let normal: ColorState?
  58. struct ColorState: Codable {
  59. let dark: ColorInfo?
  60. let universal: ColorInfo?
  61. struct ColorInfo: Codable {
  62. var hex: String?
  63. var alpha: Float?
  64. }
  65. }
  66. }
  67. struct Background: Codable {
  68. let color: Color?
  69. let layer: Layer?
  70. struct Layer: Codable {
  71. let cornerRadius: CGFloat?
  72. let borderWidth: CGFloat?
  73. let borderColor: Color?
  74. }
  75. }
  76. struct Image: Codable {
  77. let height: Language?
  78. let normal: Language?
  79. let background: Background?
  80. }
  81. struct Language: Codable {
  82. let en: String?
  83. let zh_TW: String?
  84. let zh_CN: String?
  85. }
  86. }