Created
November 20, 2019 04:26
-
-
Save dhaneshgosai/ac8415dbe9bf24d46f189ae6481d2f57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ItunesAppInfoItunes.swift | |
// | |
// Created by CodeChanger on 03/11/19. | |
// Copyright © 2019 CodeChanger. All rights reserved. | |
// | |
import Foundation | |
class ItunesAppInfoItunes : NSObject, NSCoding{ | |
var resultCount : Int! | |
var results : [ItunesAppInfoResult]! | |
/** | |
* Instantiate the instance using the passed dictionary values to set the properties values | |
*/ | |
init(fromDictionary dictionary: [String:Any]){ | |
resultCount = dictionary["resultCount"] as? Int | |
results = [ItunesAppInfoResult]() | |
if let resultsArray = dictionary["results"] as? [[String:Any]]{ | |
for dic in resultsArray{ | |
let value = ItunesAppInfoResult(fromDictionary: dic) | |
results.append(value) | |
} | |
} | |
} | |
/** | |
* 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 resultCount != nil{ | |
dictionary["resultCount"] = resultCount | |
} | |
if results != nil{ | |
var dictionaryElements = [[String:Any]]() | |
for resultsElement in results { | |
dictionaryElements.append(resultsElement.toDictionary()) | |
} | |
dictionary["results"] = dictionaryElements | |
} | |
return dictionary | |
} | |
/** | |
* NSCoding required initializer. | |
* Fills the data from the passed decoder | |
*/ | |
@objc required init(coder aDecoder: NSCoder) | |
{ | |
resultCount = aDecoder.decodeObject(forKey: "resultCount") as? Int | |
results = aDecoder.decodeObject(forKey: "results") as? [ItunesAppInfoResult] | |
} | |
/** | |
* NSCoding required method. | |
* Encodes mode properties into the decoder | |
*/ | |
@objc func encode(with aCoder: NSCoder) | |
{ | |
if resultCount != nil{ | |
aCoder.encode(resultCount, forKey: "resultCount") | |
} | |
if results != nil{ | |
aCoder.encode(results, forKey: "results") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment