I have:
let countries : [[String : Any]] = [
[
"name" : "Afghanistan",
"dial_code": "+93",
"code": "AF"
],
[
"name": "Aland Islands",
"dial_code": "+358",
"code": "AX"
],
[
"name": "Albania",
"dial_code": "+355",
"code": "AL"
],
[
"name": "Algeria",
"dial_code": "+213",
"code": "DZ"
]
]
I want to add all this array of dictionary to my custom object like
let country:[Country] = countries
My custom object looks like this:
class Country: NSObject {
let name: String
let dial_code : String
let code: String
init(name: String, dial_code: String, code: String) {
self.name = name
self.dial_code = dial_code
self.code = code
}
}
I understand that I need a loop thru the array but idk what is the next step. Would be great to have an example.
var countries = [Country](); for countryDict in countries { let aCountry = Country.init(name: countryDict["name"] dial_code:countryDict["dial_code"] code:countryDict[code"]); countries.append(aCountry);}. Code written here, might not compile but it's to give you the idea.