Blame view

App/model/ShootItem.swift 1.37 KB
defd9642e   Trịnh Văn Quân   version 1.2
1
2
3
4
5
6
7
8
9
  import Foundation
  import GeneralUtils
  
  class ShootItem: Equatable, Mappable {
      var id: Int?
      var name: String?
      var willShoot: Int?
      var signboard: Int?
      var imgs: [ImgObj]?
fbd62afcf   Trịnh Văn Quân   version 1.2.2
10
11
12
      var date: Double?
      var note: String?
      var dateStr: String?
defd9642e   Trịnh Văn Quân   version 1.2
13

fbd62afcf   Trịnh Văn Quân   version 1.2.2
14
      init(id: Int? = nil, name: String? = nil, willShoot: Int? = nil) {
defd9642e   Trịnh Văn Quân   version 1.2
15
16
          self.id = id
          self.name = name
fbd62afcf   Trịnh Văn Quân   version 1.2.2
17
          self.willShoot = willShoot;
defd9642e   Trịnh Văn Quân   version 1.2
18
19
20
21
22
23
      }
  
      func addImg(img: ImgObj) {
          if imgs == nil { imgs = [ImgObj]() }
          imgs?.append(img)
      }
fbd62afcf   Trịnh Văn Quân   version 1.2.2
24
25
26
27
28
29
30
31
      func toDic() -> [String: Any] {
          var willShoot = (self.willShoot == nil) ? 0 : 1
          var params: [String: Any] = ["name": name!, "willShoot": willShoot];
          if let id = self.id {
              params["id"] = id;
          }
          return params;
      }
defd9642e   Trịnh Văn Quân   version 1.2
32
33
34
35
36
37
38
39
40
      // region: ========== Mappable
      init() {}
      required init?(map: Map) {}
  
      func mapping(map: Map) {
          id <- map["id"]
          name <- map["name"]
          willShoot <- map["willShoot"]
          imgs <- map["imgs"]
fbd62afcf   Trịnh Văn Quân   version 1.2.2
41
42
43
44
45
          dateStr <- map["date"]
          if let dateStr = dateStr {
              date = Double(dateStr);
          }
          note <- map["note"]
defd9642e   Trịnh Văn Quân   version 1.2
46
47
48
49
50
51
52
53
54
55
      }
      //endregion
  }
  
  func ==(lhs: ShootItem, rhs: ShootItem) -> Bool {
      if let lhsName = lhs.name, let rhsName = rhs.name {
          return lhsName == rhsName
      }
      return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
  }