import Foundation import SwiftyJSON class Cover : NSObject, NSCoding{ var h : Int! var img : String! var w : Int! var x : Int! var y : Int! /** * Instantiate the instance using the passed json values to set the properties values */ init(fromJson json: JSON!){ if json.isEmpty{ return } h = json["h"].intValue img = json["img"].stringValue w = json["w"].intValue x = json["x"].intValue y = json["y"].intValue } /** * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property */ func toDictionary() -> [String:Any] { var dictionary = [String:Any]() if h != nil{ dictionary["h"] = h } if img != nil{ dictionary["img"] = img } if w != nil{ dictionary["w"] = w } if x != nil{ dictionary["x"] = x } if y != nil{ dictionary["y"] = y } return dictionary } /** * NSCoding required initializer. * Fills the data from the passed decoder */ @objc required init(coder aDecoder: NSCoder) { h = aDecoder.decodeObject(forKey: "h") as? Int img = aDecoder.decodeObject(forKey: "img") as? String w = aDecoder.decodeObject(forKey: "w") as? Int x = aDecoder.decodeObject(forKey: "x") as? Int y = aDecoder.decodeObject(forKey: "y") as? Int } /** * NSCoding required method. * Encodes mode properties into the decoder */ func encode(with aCoder: NSCoder) { if h != nil{ aCoder.encode(h, forKey: "h") } if img != nil{ aCoder.encode(img, forKey: "img") } if w != nil{ aCoder.encode(w, forKey: "w") } if x != nil{ aCoder.encode(x, forKey: "x") } if y != nil{ aCoder.encode(y, forKey: "y") } } }