Hello I am using SwiftyJSONAccelerator Tool for crating model but its create memory leak.
Please review below code.
If I will comment above two lines than Memory leak is remove.
public final class InternationalPackage: NSCoding {
// MARK: Declaration for string constants to be used to decode and also serialize.
private struct SerializationKeys {
static let status = "status"
static let data = "data"
static let message = "message"
static let currencyImage = "CurrencyImage"
static let isUser = "IsUser"
}
// MARK: Properties
public var status : Int?
public var data : [InternationalpackageData]?
public var message : String?
public var currencyImage: [CurrencyImage]?
public var isUser : Int?
// MARK: SwiftyJSON Initializers
/// Initiates the instance based on the object.
///
/// - parameter object: The object of either Dictionary or Array kind that was passed.
/// - returns: An initialized instance of the class.
public convenience init(object: Any) {
self.init(json: JSON(object))
}
/// Initiates the instance based on the JSON that was passed.
///
/// - parameter json: JSON object from SwiftyJSON.
public required init(json: JSON) {
status = json[SerializationKeys.status].int
if let items = json[SerializationKeys.data].array { data = items.map { InternationalpackageData(json: $0) } }
message = json[SerializationKeys.message].string
if let items = json[SerializationKeys.currencyImage].array { currencyImage = items.map { CurrencyImage(json: $0) } }
isUser = json[SerializationKeys.isUser].int
}
/// Generates description of the object in the form of a NSDictionary.
///
/// - returns: A Key value pair containing all valid values in the object.
public func dictionaryRepresentation() -> [String: Any] {
var dictionary: [String: Any] = [:]
if let value = status { dictionary[SerializationKeys.status] = value }
if let value = data { dictionary[SerializationKeys.data] = value.map { $0.dictionaryRepresentation() } }
if let value = message { dictionary[SerializationKeys.message] = value }
if let value = currencyImage { dictionary[SerializationKeys.currencyImage] = value.map { $0.dictionaryRepresentation() } }
if let value = isUser { dictionary[SerializationKeys.isUser] = value }
return dictionary
}
// MARK: NSCoding Protocol
required public init(coder aDecoder: NSCoder) {
self.status = aDecoder.decodeObject(forKey: SerializationKeys.status) as? Int
self.data = aDecoder.decodeObject(forKey: SerializationKeys.data) as? [InternationalpackageData]
self.message = aDecoder.decodeObject(forKey: SerializationKeys.message) as? String
self.currencyImage = aDecoder.decodeObject(forKey: SerializationKeys.currencyImage) as? [CurrencyImage]
self.isUser = aDecoder.decodeObject(forKey: SerializationKeys.isUser) as? Int
}
public func encode(with aCoder: NSCoder) {
aCoder.encode(status, forKey: SerializationKeys.status)
aCoder.encode(data, forKey: SerializationKeys.data)
aCoder.encode(message, forKey: SerializationKeys.message)
aCoder.encode(currencyImage, forKey: SerializationKeys.currencyImage)
aCoder.encode(isUser, forKey: SerializationKeys.isUser)
}
}