CMSData.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // CMSData.swift
  3. // Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
  4. import Foundation
  5. import ObjectMapper
  6. // MARK: - Helper functions for creating encoders and decoders
  7. func newJSONDecoder() -> JSONDecoder {
  8. let decoder = JSONDecoder()
  9. if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
  10. decoder.dateDecodingStrategy = .iso8601
  11. }
  12. return decoder
  13. }
  14. func newJSONEncoder() -> JSONEncoder {
  15. let encoder = JSONEncoder()
  16. if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
  17. encoder.dateEncodingStrategy = .iso8601
  18. }
  19. return encoder
  20. }
  21. //cms 栏目的配置文件 存在CMSData栏目对象中的config这个字读啊
  22. struct CMSAppConfig: Codable {
  23. let ignoreTitle: Bool? //是否要填写文档标题
  24. let latest: Bool? //是否忽略草稿
  25. init(_ json: String, using encoding: String.Encoding = .utf8) throws {
  26. guard let data = json.data(using: encoding) else {
  27. throw NSError(domain: "JSONDecoding", code: 0, userInfo: nil)
  28. }
  29. try self.init(data: data)
  30. }
  31. init(data: Data) throws {
  32. self = try newJSONDecoder().decode(CMSAppConfig.self, from: data)
  33. }
  34. init(fromURL url: URL) throws {
  35. try self.init(data: try Data(contentsOf: url))
  36. }
  37. func jsonData() throws -> Data {
  38. return try newJSONEncoder().encode(self)
  39. }
  40. func jsonString(encoding: String.Encoding = .utf8) throws -> String? {
  41. return String(data: try self.jsonData(), encoding: encoding)
  42. }
  43. }
  44. class CMSData: NSObject, NSCoding, Mappable {
  45. var appAlias: String?
  46. var appIcon: String?
  47. var appInfoSeq: String?
  48. var appName: String?
  49. var categoryList: [AnyObject]?
  50. var createTime: String?
  51. var creatorCompany: String?
  52. var creatorDepartment: String?
  53. var creatorIdentity: String?
  54. var creatorPerson: String?
  55. var descriptionField: String?
  56. var distributeFactor: Int?
  57. var id: String?
  58. var sequence: String?
  59. var updateTime: String?
  60. var config: String? //配置参数用的 json字符串
  61. var wrapOutCategoryList: [CMSWrapOutCategoryList]?
  62. class func newInstance(map: Map) -> Mappable? {
  63. return CMSData()
  64. }
  65. required init?(map: Map) { }
  66. private override init() { }
  67. func mapping(map: Map)
  68. {
  69. appAlias <- map["appAlias"]
  70. appIcon <- map["appIcon"]
  71. appInfoSeq <- map["appInfoSeq"]
  72. appName <- map["appName"]
  73. categoryList <- map["categoryList"]
  74. createTime <- map["createTime"]
  75. creatorCompany <- map["creatorCompany"]
  76. creatorDepartment <- map["creatorDepartment"]
  77. creatorIdentity <- map["creatorIdentity"]
  78. creatorPerson <- map["creatorPerson"]
  79. descriptionField <- map["description"]
  80. distributeFactor <- map["distributeFactor"]
  81. id <- map["id"]
  82. sequence <- map["sequence"]
  83. updateTime <- map["updateTime"]
  84. config <- map["config"]
  85. wrapOutCategoryList <- map["wrapOutCategoryList"]
  86. }
  87. /**
  88. * NSCoding required initializer.
  89. * Fills the data from the passed decoder
  90. */
  91. @objc required init(coder aDecoder: NSCoder)
  92. {
  93. appAlias = aDecoder.decodeObject(forKey: "appAlias") as? String
  94. appIcon = aDecoder.decodeObject(forKey: "appIcon") as? String
  95. appInfoSeq = aDecoder.decodeObject(forKey: "appInfoSeq") as? String
  96. appName = aDecoder.decodeObject(forKey: "appName") as? String
  97. categoryList = aDecoder.decodeObject(forKey: "categoryList") as? [AnyObject]
  98. createTime = aDecoder.decodeObject(forKey: "createTime") as? String
  99. creatorCompany = aDecoder.decodeObject(forKey: "creatorCompany") as? String
  100. creatorDepartment = aDecoder.decodeObject(forKey: "creatorDepartment") as? String
  101. creatorIdentity = aDecoder.decodeObject(forKey: "creatorIdentity") as? String
  102. creatorPerson = aDecoder.decodeObject(forKey: "creatorPerson") as? String
  103. descriptionField = aDecoder.decodeObject(forKey: "description") as? String
  104. distributeFactor = aDecoder.decodeObject(forKey: "distributeFactor") as? Int
  105. id = aDecoder.decodeObject(forKey: "id") as? String
  106. sequence = aDecoder.decodeObject(forKey: "sequence") as? String
  107. updateTime = aDecoder.decodeObject(forKey: "updateTime") as? String
  108. config = aDecoder.decodeObject(forKey: "config") as? String
  109. wrapOutCategoryList = aDecoder.decodeObject(forKey: "wrapOutCategoryList") as? [CMSWrapOutCategoryList]
  110. }
  111. /**
  112. * NSCoding required method.
  113. * Encodes mode properties into the decoder
  114. */
  115. @objc func encode(with aCoder: NSCoder)
  116. {
  117. if appAlias != nil {
  118. aCoder.encode(appAlias, forKey: "appAlias")
  119. }
  120. if appIcon != nil {
  121. aCoder.encode(appIcon, forKey: "appIcon")
  122. }
  123. if appInfoSeq != nil {
  124. aCoder.encode(appInfoSeq, forKey: "appInfoSeq")
  125. }
  126. if appName != nil {
  127. aCoder.encode(appName, forKey: "appName")
  128. }
  129. if categoryList != nil {
  130. aCoder.encode(categoryList, forKey: "categoryList")
  131. }
  132. if createTime != nil {
  133. aCoder.encode(createTime, forKey: "createTime")
  134. }
  135. if creatorCompany != nil {
  136. aCoder.encode(creatorCompany, forKey: "creatorCompany")
  137. }
  138. if creatorDepartment != nil {
  139. aCoder.encode(creatorDepartment, forKey: "creatorDepartment")
  140. }
  141. if creatorIdentity != nil {
  142. aCoder.encode(creatorIdentity, forKey: "creatorIdentity")
  143. }
  144. if creatorPerson != nil {
  145. aCoder.encode(creatorPerson, forKey: "creatorPerson")
  146. }
  147. if descriptionField != nil {
  148. aCoder.encode(descriptionField, forKey: "description")
  149. }
  150. if distributeFactor != nil {
  151. aCoder.encode(distributeFactor, forKey: "distributeFactor")
  152. }
  153. if id != nil {
  154. aCoder.encode(id, forKey: "id")
  155. }
  156. if sequence != nil {
  157. aCoder.encode(sequence, forKey: "sequence")
  158. }
  159. if updateTime != nil {
  160. aCoder.encode(updateTime, forKey: "updateTime")
  161. }
  162. if config != nil {
  163. aCoder.encode(config, forKey: "config")
  164. }
  165. if wrapOutCategoryList != nil {
  166. aCoder.encode(wrapOutCategoryList, forKey: "wrapOutCategoryList")
  167. }
  168. }
  169. }