i am new with swift , i am trying to get list of countries with Phone code example +1 or +92 , i am trying to print our with :
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
let phoneCode = carrier?.mobileNetworkCode
print(phoneCode)
let countryCode = NSLocale.isoCountryCodes
for country in countryCode {
print(country)
}
phoneCode output is 03 which is wrong it should be +961
and the result of country is ios name 2 , example ZA,YT etc how to get full country name ? should i use custom JSON !
Try This dictionary with [country:code] to get country name and country phone code.
class CountryPhoneCodeAndName: NSObject {
var countryWithCode = [CountryNameWithCode]()
var countryDictionary = ["AF":"93", "AL":"355", "DZ":"213","AS":"1", "AD":"376", "AO":"244", "AI":"1","AG":"1","AR":"54","AM":"374","AW":"297","AU":"61","AT":"43","AZ":"994","BS":"1","BH":"973","BD":"880","BB":"1","BY":"375","BE":"32","BZ":"501","BJ":"229","BM":"1","BT":"975","BA":"387","BW":"267","BR":"55","IO":"246","BG":"359","BF":"226","BI":"257","KH":"855","CM":"237","CA":"1","CV":"238","KY":"345","CF":"236","TD":"235","CL":"56","CN":"86","CX":"61","CO":"57","KM":"269","CG":"242","CK":"682","CR":"506","HR":"385","CU":"53","CY":"537","CZ":"420","DK":"45","DJ":"253","DM":"1","DO":"1","EC":"593","EG":"20","SV":"503","GQ":"240","ER":"291","EE":"372","ET":"251","FO":"298","FJ":"679","FI":"358","FR":"33","GF":"594","PF":"689","GA":"241","GM":"220","GE":"995","DE":"49","GH":"233","GI":"350","GR":"30","GL":"299","GD":"1","GP":"590","GU":"1","GT":"502","GN":"224","GW":"245","GY":"595","HT":"509","HN":"504","HU":"36","IS":"354","IN":"91","ID":"62","IQ":"964","IE":"353","IL":"972","IT":"39","JM":"1","JP":"81","JO":"962","KZ":"77","KE":"254","KI":"686","KW":"965","KG":"996","LV":"371","LB":"961","LS":"266","LR":"231","LI":"423","LT":"370","LU":"352","MG":"261","MW":"265","MY":"60","MV":"960","ML":"223","MT":"356","MH":"692","MQ":"596","MR":"222","MU":"230","YT":"262","MX":"52","MC":"377","MN":"976","ME":"382","MS":"1","MA":"212","MM":"95","NA":"264","NR":"674","NP":"977","NL":"31","AN":"599","NC":"687","NZ":"64","NI":"505","NE":"227","NG":"234","NU":"683","NF":"672","MP":"1","NO":"47","OM":"968","PK":"92","PW":"680","PA":"507","PG":"675","PY":"595","PE":"51","PH":"63","PL":"48","PT":"351","PR":"1","QA":"974","RO":"40","RW":"250","WS":"685","SM":"378","SA":"966","SN":"221","RS":"381","SC":"248","SL":"232","SG":"65","SK":"421","SI":"386","SB":"677","ZA":"27","GS":"500","ES":"34","LK":"94","SD":"249","SR":"597","SZ":"268","SE":"46","CH":"41","TJ":"992","TH":"66","TG":"228","TK":"690","TO":"676","TT":"1","TN":"216","TR":"90","TM":"993","TC":"1","TV":"688","UG":"256","UA":"380","AE":"971","GB":"44","US":"1", "UY":"598","UZ":"998", "VU":"678", "WF":"681","YE":"967","ZM":"260","ZW":"263","BO":"591","BN":"673","CC":"61","CD":"243","CI":"225","FK":"500","GG":"44","VA":"379","HK":"852","IR":"98","IM":"44","JE":"44","KP":"850","KR":"82","LA":"856","LY":"218","MO":"853","MK":"389","FM":"691","MD":"373","MZ":"258","PS":"970","PN":"872","RE":"262","RU":"7","BL":"590","SH":"290","KN":"1","LC":"1","MF":"590","PM":"508","VC":"1","ST":"239","SO":"252","SJ":"47","SY":"963","TW":"886","TZ":"255","TL":"670","VE":"58","VN":"84","VG":"284","VI":"340"]
func getCountryName() {
// Sorting all keys
let keys = countryDictionary.keys
let keysValue = keys.sorted { (first, second) -> Bool in
let key1: String = first
let key2: String = second
let result = key1.compare(key2) == .orderedAscending
return result
}
print(keysValue)
for key in keysValue{
let countryKeyValue = CountryNameWithCode()
print(countryDictionary[key] ?? "not")
countryKeyValue.countryCode = countryDictionary[key]!
countryKeyValue.countryName = Locale.current.localizedString(forRegionCode: key)!
print(Locale.current.localizedString(forRegionCode: key)!)
countryWithCode.append(countryKeyValue)
}
}
class CountryNameWithCode: NSObject {
var countryName = ""
var countryCode = ""
}
}
Here It is the list of country codes JSON
[ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Åland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" }, { "name": "Bahrain", "dial_code": "+973", "code": "BH" }, { "name": "Bangladesh", "dial_code": "+880", "code": "BD" }, { "name": "Barbados", "dial_code": "+1246", "code": "BB" }, { "name": "Belarus", "dial_code": "+375", "code": "BY" }, { "name": "Belgium", "dial_code": "+32", "code": "BE" }, { "name": "Belize", "dial_code": "+501", "code": "BZ" }, { "name": "Benin", "dial_code": "+229", "code": "BJ" }, { "name": "Bermuda", "dial_code": "+1441", "code": "BM" }, { "name": "Bhutan", "dial_code": "+975", "code": "BT" }, { "name": "Bolivia, Plurinational State of bolivia", "dial_code": "+591", "code": "BO" }, { "name": "Bosnia and Herzegovina", "dial_code": "+387", "code": "BA" }, { "name": "Botswana", "dial_code": "+267", "code": "BW" }, { "name": "Bouvet Island", "dial_code": "+47", "code": "BV" }, { "name": "Brazil", "dial_code": "+55", "code": "BR" }, { "name": "British Indian Ocean Territory", "dial_code": "+246", "code": "IO" }, { "name": "Brunei Darussalam", "dial_code": "+673", "code": "BN" }, { "name": "Bulgaria", "dial_code": "+359", "code": "BG" }, { "name": "Burkina Faso", "dial_code": "+226", "code": "BF" }, { "name": "Burundi", "dial_code": "+257", "code": "BI" }, { "name": "Cambodia", "dial_code": "+855", "code": "KH" }, { "name": "Cameroon", "dial_code": "+237", "code": "CM" }, { "name": "Canada", "dial_code": "+1", "code": "CA" }, { "name": "Cape Verde", "dial_code": "+238", "code": "CV" }, { "name": "Cayman Islands", "dial_code": "+ 345", "code": "KY" }, { "name": "Central African Republic", "dial_code": "+236", "code": "CF" }, { "name": "Chad", "dial_code": "+235", "code": "TD" }, { "name": "Chile", "dial_code": "+56", "code": "CL" }, { "name": "China", "dial_code": "+86", "code": "CN" }, { "name": "Christmas Island", "dial_code": "+61", "code": "CX" }, { "name": "Cocos (Keeling) Islands", "dial_code": "+61", "code": "CC" }, { "name": "Colombia", "dial_code": "+57", "code": "CO" }, { "name": "Comoros", "dial_code": "+269", "code": "KM" }, { "name": "Congo", "dial_code": "+242", "code": "CG" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "+243", "code": "CD" }, { "name": "Cook Islands", "dial_code": "+682", "code": "CK" }, { "name": "Costa Rica", "dial_code": "+506", "code": "CR" }, { "name": "Cote d'Ivoire", "dial_code": "+225", "code": "CI" }, { "name": "Croatia", "dial_code": "+385", "code": "HR" }, { "name": "Cuba", "dial_code": "+53", "code": "CU" }, { "name": "Cyprus", "dial_code": "+357", "code": "CY" }, { "name": "Czech Republic", "dial_code": "+420", "code": "CZ" }, { "name": "Denmark", "dial_code": "+45", "code": "DK" }, { "name": "Djibouti", "dial_code": "+253", "code": "DJ" }, { "name": "Dominica", "dial_code": "+1767", "code": "DM" }, { "name": "Dominican Republic", "dial_code": "+1849", "code": "DO" }, { "name": "Ecuador", "dial_code": "+593", "code": "EC" }, { "name": "Egypt", "dial_code": "+20", "code": "EG" }, { "name": "El Salvador", "dial_code": "+503", "code": "SV" }, { "name": "Equatorial Guinea", "dial_code": "+240", "code": "GQ" }, { "name": "Eritrea", "dial_code": "+291", "code": "ER" }, { "name": "Estonia", "dial_code": "+372", "code": "EE" }, { "name": "Ethiopia", "dial_code": "+251", "code": "ET" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK" }, { "name": "Faroe Islands", "dial_code": "+298", "code": "FO" }, { "name": "Fiji", "dial_code": "+679", "code": "FJ" }, { "name": "Finland", "dial_code": "+358", "code": "FI" }, { "name": "France", "dial_code": "+33", "code": "FR" }, { "name": "French Guiana", "dial_code": "+594", "code": "GF" }, { "name": "French Polynesia", "dial_code": "+689", "code": "PF" }, { "name": "French Southern Territories", "dial_code": "+262", "code": "TF" }, { "name": "Gabon", "dial_code": "+241", "code": "GA" }, { "name": "Gambia", "dial_code": "+220", "code": "GM" }, { "name": "Georgia", "dial_code": "+995", "code": "GE" }, { "name": "Germany", "dial_code": "+49", "code": "DE" }, { "name": "Ghana", "dial_code": "+233", "code": "GH" }, { "name": "Gibraltar", "dial_code": "+350", "code": "GI" }, { "name": "Greece", "dial_code": "+30", "code": "GR" }, { "name": "Greenland", "dial_code": "+299", "code": "GL" }, { "name": "Grenada", "dial_code": "+1473", "code": "GD" }, { "name": "Guadeloupe", "dial_code": "+590", "code": "GP" }, { "name": "Guam", "dial_code": "+1671", "code": "GU" }, { "name": "Guatemala", "dial_code": "+502", "code": "GT" }, { "name": "Guernsey", "dial_code": "+44", "code": "GG" }, { "name": "Guinea", "dial_code": "+224", "code": "GN" }, { "name": "Guinea-Bissau", "dial_code": "+245", "code": "GW" }, { "name": "Guyana", "dial_code": "+592", "code": "GY" }, { "name": "Haiti", "dial_code": "+509", "code": "HT" }, { "name": "Heard Island and Mcdonald Islands", "dial_code": "+0", "code": "HM" }, { "name": "Holy See (Vatican City State)", "dial_code": "+379", "code": "VA" }, { "name": "Honduras", "dial_code": "+504", "code": "HN" }, { "name": "Hong Kong", "dial_code": "+852", "code": "HK" }, { "name": "Hungary", "dial_code": "+36", "code": "HU" }, { "name": "Iceland", "dial_code": "+354", "code": "IS" }, { "name": "India", "dial_code": "+91", "code": "IN" }, { "name": "Indonesia", "dial_code": "+62", "code": "ID" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "+98", "code": "IR" }, { "name": "Iraq", "dial_code": "+964", "code": "IQ" }, { "name": "Ireland", "dial_code": "+353", "code": "IE" }, { "name": "Isle of Man", "dial_code": "+44", "code": "IM" }, { "name": "Israel", "dial_code": "+972", "code": "IL" }, { "name": "Italy", "dial_code": "+39", "code": "IT" }, { "name": "Jamaica", "dial_code": "+1876", "code": "JM" }, { "name": "Japan", "dial_code": "+81", "code": "JP" }, { "name": "Jersey", "dial_code": "+44", "code": "JE" }, { "name": "Jordan", "dial_code": "+962", "code": "JO" }, { "name": "Kazakhstan", "dial_code": "+7", "code": "KZ" }, { "name": "Kenya", "dial_code": "+254", "code": "KE" }, { "name": "Kiribati", "dial_code": "+686", "code": "KI" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "+850", "code": "KP" }, { "name": "Korea, Republic of South Korea", "dial_code": "+82", "code": "KR" }, { "name": "Kosovo", "dial_code": "+383", "code": "XK" }, { "name": "Kuwait", "dial_code": "+965", "code": "KW" }, { "name": "Kyrgyzstan", "dial_code": "+996", "code": "KG" }, { "name": "Laos", "dial_code": "+856", "code": "LA" }, { "name": "Latvia", "dial_code": "+371", "code": "LV" }, { "name": "Lebanon", "dial_code": "+961", "code": "LB" }, { "name": "Lesotho", "dial_code": "+266", "code": "LS" }, { "name": "Liberia", "dial_code": "+231", "code": "LR" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "+218", "code": "LY" }, { "name": "Liechtenstein", "dial_code": "+423", "code": "LI" }, { "name": "Lithuania", "dial_code": "+370", "code": "LT" }, { "name": "Luxembourg", "dial_code": "+352", "code": "LU" }, { "name": "Macao", "dial_code": "+853", "code": "MO" }, { "name": "Macedonia", "dial_code": "+389", "code": "MK" }, { "name": "Madagascar", "dial_code": "+261", "code": "MG" }, { "name": "Malawi", "dial_code": "+265", "code": "MW" }, { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, { "name": "Maldives", "dial_code": "+960", "code": "MV" }, { "name": "Mali", "dial_code": "+223", "code": "ML" }, { "name": "Malta", "dial_code": "+356", "code": "MT" }, { "name": "Marshall Islands", "dial_code": "+692", "code": "MH" }, { "name": "Martinique", "dial_code": "+596", "code": "MQ" }, { "name": "Mauritania", "dial_code": "+222", "code": "MR" }, { "name": "Mauritius", "dial_code": "+230", "code": "MU" }, { "name": "Mayotte", "dial_code": "+262", "code": "YT" }, { "name": "Mexico", "dial_code": "+52", "code": "MX" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "+691", "code": "FM" }, { "name": "Moldova", "dial_code": "+373", "code": "MD" }, { "name": "Monaco", "dial_code": "+377", "code": "MC" }, { "name": "Mongolia", "dial_code": "+976", "code": "MN" }, { "name": "Montenegro", "dial_code": "+382", "code": "ME" }, { "name": "Montserrat", "dial_code": "+1664", "code": "MS" }, { "name": "Morocco", "dial_code": "+212", "code": "MA" }, { "name": "Mozambique", "dial_code": "+258", "code": "MZ" }, { "name": "Myanmar", "dial_code": "+95", "code": "MM" }, { "name": "Namibia", "dial_code": "+264", "code": "NA" }, { "name": "Nauru", "dial_code": "+674", "code": "NR" }, { "name": "Nepal", "dial_code": "+977", "code": "NP" }, { "name": "Netherlands", "dial_code": "+31", "code": "NL" }, { "name": "Netherlands Antilles", "dial_code": "+599", "code": "AN" }, { "name": "New Caledonia", "dial_code": "+687", "code": "NC" }, { "name": "New Zealand", "dial_code": "+64", "code": "NZ" }, { "name": "Nicaragua", "dial_code": "+505", "code": "NI" }, { "name": "Niger", "dial_code": "+227", "code": "NE" }, { "name": "Nigeria", "dial_code": "+234", "code": "NG" }, { "name": "Niue", "dial_code": "+683", "code": "NU" }, { "name": "Norfolk Island", "dial_code": "+672", "code": "NF" }, { "name": "Northern Mariana Islands", "dial_code": "+1670", "code": "MP" }, { "name": "Norway", "dial_code": "+47", "code": "NO" }, { "name": "Oman", "dial_code": "+968", "code": "OM" }, { "name": "Pakistan", "dial_code": "+92", "code": "PK" }, { "name": "Palau", "dial_code": "+680", "code": "PW" }, { "name": "Palestinian Territory, Occupied", "dial_code": "+970", "code": "PS" }, { "name": "Panama", "dial_code": "+507", "code": "PA" }, { "name": "Papua New Guinea", "dial_code": "+675", "code": "PG" }, { "name": "Paraguay", "dial_code": "+595", "code": "PY" }, { "name": "Peru", "dial_code": "+51", "code": "PE" }, { "name": "Philippines", "dial_code": "+63", "code": "PH" }, { "name": "Pitcairn", "dial_code": "+64", "code": "PN" }, { "name": "Poland", "dial_code": "+48", "code": "PL" }, { "name": "Portugal", "dial_code": "+351", "code": "PT" }, { "name": "Puerto Rico", "dial_code": "+1939", "code": "PR" }, { "name": "Qatar", "dial_code": "+974", "code": "QA" }, { "name": "Romania", "dial_code": "+40", "code": "RO" }, { "name": "Russia", "dial_code": "+7", "code": "RU" }, { "name": "Rwanda", "dial_code": "+250", "code": "RW" }, { "name": "Reunion", "dial_code": "+262", "code": "RE" }, { "name": "Saint Barthelemy", "dial_code": "+590", "code": "BL" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "+290", "code": "SH" }, { "name": "Saint Kitts and Nevis", "dial_code": "+1869", "code": "KN" }, { "name": "Saint Lucia", "dial_code": "+1758", "code": "LC" }, { "name": "Saint Martin", "dial_code": "+590", "code": "MF" }, { "name": "Saint Pierre and Miquelon", "dial_code": "+508", "code": "PM" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "+1784", "code": "VC" }, { "name": "Samoa", "dial_code": "+685", "code": "WS" }, { "name": "San Marino", "dial_code": "+378", "code": "SM" }, { "name": "Sao Tome and Principe", "dial_code": "+239", "code": "ST" }, { "name": "Saudi Arabia", "dial_code": "+966", "code": "SA" }, { "name": "Senegal", "dial_code": "+221", "code": "SN" }, { "name": "Serbia", "dial_code": "+381", "code": "RS" }, { "name": "Seychelles", "dial_code": "+248", "code": "SC" }, { "name": "Sierra Leone", "dial_code": "+232", "code": "SL" }, { "name": "Singapore", "dial_code": "+65", "code": "SG" }, { "name": "Slovakia", "dial_code": "+421", "code": "SK" }, { "name": "Slovenia", "dial_code": "+386", "code": "SI" }, { "name": "Solomon Islands", "dial_code": "+677", "code": "SB" }, { "name": "Somalia", "dial_code": "+252", "code": "SO" }, { "name": "South Africa", "dial_code": "+27", "code": "ZA" }, { "name": "South Sudan", "dial_code": "+211", "code": "SS" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "+500", "code": "GS" }, { "name": "Spain", "dial_code": "+34", "code": "ES" }, { "name": "Sri Lanka", "dial_code": "+94", "code": "LK" }, { "name": "Sudan", "dial_code": "+249", "code": "SD" }, { "name": "Suriname", "dial_code": "+597", "code": "SR" }, { "name": "Svalbard and Jan Mayen", "dial_code": "+47", "code": "SJ" }, { "name": "Swaziland", "dial_code": "+268", "code": "SZ" }, { "name": "Sweden", "dial_code": "+46", "code": "SE" }, { "name": "Switzerland", "dial_code": "+41", "code": "CH" }, { "name": "Syrian Arab Republic", "dial_code": "+963", "code": "SY" }, { "name": "Taiwan", "dial_code": "+886", "code": "TW" }, { "name": "Tajikistan", "dial_code": "+992", "code": "TJ" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "+255", "code": "TZ" }, { "name": "Thailand", "dial_code": "+66", "code": "TH" }, { "name": "Timor-Leste", "dial_code": "+670", "code": "TL" }, { "name": "Togo", "dial_code": "+228", "code": "TG" }, { "name": "Tokelau", "dial_code": "+690", "code": "TK" }, { "name": "Tonga", "dial_code": "+676", "code": "TO" }, { "name": "Trinidad and Tobago", "dial_code": "+1868", "code": "TT" }, { "name": "Tunisia", "dial_code": "+216", "code": "TN" }, { "name": "Turkey", "dial_code": "+90", "code": "TR" }, { "name": "Turkmenistan", "dial_code": "+993", "code": "TM" }, { "name": "Turks and Caicos Islands", "dial_code": "+1649", "code": "TC" }, { "name": "Tuvalu", "dial_code": "+688", "code": "TV" }, { "name": "Uganda", "dial_code": "+256", "code": "UG" }, { "name": "Ukraine", "dial_code": "+380", "code": "UA" }, { "name": "United Arab Emirates", "dial_code": "+971", "code": "AE" }, { "name": "United Kingdom", "dial_code": "+44", "code": "GB" }, { "name": "United States", "dial_code": "+1", "code": "US" }, { "name": "Uruguay", "dial_code": "+598", "code": "UY" }, { "name": "Uzbekistan", "dial_code": "+998", "code": "UZ" }, { "name": "Vanuatu", "dial_code": "+678", "code": "VU" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "+58", "code": "VE" }, { "name": "Vietnam", "dial_code": "+84", "code": "VN" }, { "name": "Virgin Islands, British", "dial_code": "+1284", "code": "VG" }, { "name": "Virgin Islands, U.S.", "dial_code": "+1340", "code": "VI" }, { "name": "Wallis and Futuna", "dial_code": "+681", "code": "WF" }, { "name": "Yemen", "dial_code": "+967", "code": "YE" }, { "name": "Zambia", "dial_code": "+260", "code": "ZM" }, { "name": "Zimbabwe", "dial_code": "+263", "code": "ZW" } ]
You can get full country name with:
let networkInformation = CTTelephonyNetworkInfo()
if let carrier = networkInformation.subscriberCellularProvider {
print("phone code:" + carrier.mobileNetworkCode!)
print("ISO country code: " + carrier.isoCountryCode!)
// Convert ISO country code to full country name
let currentLocale = NSLocale.init(localeIdentifier: NSLocale.current.identifier)
let fullCountryName = currentLocale.displayName(forKey: NSLocale.Key.countryCode, value: carrier.isoCountryCode!)
print(fullCountryName)
}
And for country prefix number I think the best way is to use custom dictionary with [country:code] values.
I did it in this simple way:
struct CountryCodeCategory {
let id: Int
let name: String
let countries: [CountryCode]
}
struct CountryCode {
let id: Int
let code: String
let name: String
let categoryId: Int
}
class CountryCodeList{
let categories = [
CountryCodeCategory(id: 0, name: "A", countries: [
CountryCode(id: 0, code: "+7 840", name: "Abkhazia", categoryId: 0),
CountryCode(id: 1, code: "+93", name: "Afghanistan", categoryId: 0),
CountryCode(id: 2, code: "+355", name: "Albania", categoryId: 0),
CountryCode(id: 3, code: "+213", name: "Algeria", categoryId: 0),
CountryCode(id: 4, code: "+1 684", name: "American Samoa", categoryId: 0),
CountryCode(id: 5, code: "+376", name: "Andorra", categoryId: 0),
CountryCode(id: 6, code: "+244", name: "Angola", categoryId: 0),
CountryCode(id: 7, code: "+1 264", name: "Anguilla", categoryId: 0),
CountryCode(id: 8, code: "+1 268", name: "Antigua and Barbuda", categoryId: 0),
CountryCode(id: 9, code: "+54", name: "Argentina", categoryId: 0),
CountryCode(id: 10, code: "+374", name: "Armenia", categoryId: 0),
CountryCode(id: 11, code: "+297", name: "Aruba", categoryId: 0),
CountryCode(id: 12, code: "+247", name: "Ascension", categoryId: 0),
CountryCode(id: 13, code: "+61", name: "Australia", categoryId: 0),
CountryCode(id: 14, code: "+672", name: "Australian External Territories", categoryId: 0),
CountryCode(id: 15, code: "+43", name: "Austria", categoryId: 0),
CountryCode(id: 16, code: "+994", name: "Azerbaijan", categoryId: 0),
]),
CountryCodeCategory(id: 1, name: "B", countries: [
CountryCode(id: 17, code: "+1 242", name: "Bahamas", categoryId: 1),
CountryCode(id: 18, code: "+973", name: "Bahrain", categoryId: 1),
CountryCode(id: 19, code: "+880", name: "Bangladesh", categoryId: 1),
CountryCode(id: 20, code: "+1 246", name: "Barbados", categoryId: 1),
CountryCode(id: 21, code: "+1 268", name: "Barbuda", categoryId: 1),
CountryCode(id: 22, code: "+375", name: "Belarus", categoryId: 1),
CountryCode(id: 23, code: "+32", name: "Belgium", categoryId: 1),
CountryCode(id: 24, code: "+501", name: "Belize", categoryId: 1),
CountryCode(id: 25, code: "+229", name: "Benin", categoryId: 1),
CountryCode(id: 26, code: "+1 441", name: "Bermuda", categoryId: 1),
CountryCode(id: 27, code: "+975", name: "Bhutan", categoryId: 1),
CountryCode(id: 28, code: "+591", name: "Bolivia", categoryId: 1),
CountryCode(id: 29, code: "+387", name: "Bosnia and Herzegovina", categoryId: 1),
CountryCode(id: 30, code: "+267", name: "Botswana", categoryId: 1),
CountryCode(id: 31, code: "+55", name: "Brazil", categoryId: 1),
CountryCode(id: 32, code: "+246", name: "British Indian Ocean Territory", categoryId: 1),
CountryCode(id: 33, code: "+1 284", name: "British Virgin Islands", categoryId: 1),
CountryCode(id: 34, code: "+673", name: "Brunei", categoryId: 1),
CountryCode(id: 35, code: "+359", name: "Bulgaria", categoryId: 1),
CountryCode(id: 36, code: "+226", name: "Burkina Faso", categoryId: 1),
CountryCode(id: 37, code: "+257", name: "Burundi", categoryId: 1),
]),
CountryCodeCategory(id: 2, name: "C", countries: [
CountryCode(id: 38, code: "+855", name: "Cambodia", categoryId: 2),
CountryCode(id: 39, code: "+237", name: "Cameroon", categoryId: 2),
CountryCode(id: 40, code: "+1", name: "Canada", categoryId: 2),
CountryCode(id: 41, code: "+238", name: "Cape Verde", categoryId: 2),
CountryCode(id: 42, code: "+ 345", name: "Cayman Islands", categoryId: 2),
CountryCode(id: 43, code: "+236", name: "Central African Republic", categoryId: 2),
CountryCode(id: 44, code: "+235", name: "Chad", categoryId: 2),
CountryCode(id: 45, code: "+56", name: "Chile", categoryId: 2),
CountryCode(id: 46, code: "+86", name: "China", categoryId: 2),
CountryCode(id: 47, code: "+61", name: "Christmas Island", categoryId: 2),
CountryCode(id: 48, code: "+61", name: "Cocos-Keeling Islands", categoryId: 2),
CountryCode(id: 49, code: "+57", name: "Colombia", categoryId: 2),
CountryCode(id: 50, code: "+269", name: "Comoros", categoryId: 2),
CountryCode(id: 51, code: "+242", name: "Congo", categoryId: 2),
CountryCode(id: 52, code: "+243", name: "Congo, Dem. Rep. of (Zaire)", categoryId: 2),
CountryCode(id: 53, code: "+682", name: "Cook Islands", categoryId: 2),
CountryCode(id: 54, code: "+506", name: "Costa Rica", categoryId: 2),
CountryCode(id: 55, code: "+385", name: "Croatia", categoryId: 2),
CountryCode(id: 56, code: "+53", name: "Cuba", categoryId: 2),
CountryCode(id: 57, code: "+599", name: "Curacao", categoryId: 2),
CountryCode(id: 58, code: "+537", name: "Cyprus", categoryId: 2),
CountryCode(id: 59, code: "+420", name: "Czech Republic", categoryId: 2),
]),
CountryCodeCategory(id: 3, name: "D", countries: [
CountryCode(id: 60, code: "+45", name: "Denmark", categoryId: 3),
CountryCode(id: 61, code: "+246", name: "Diego Garcia", categoryId: 3),
CountryCode(id: 62, code: "+253", name: "Djibouti", categoryId: 3),
CountryCode(id: 63, code: "+1 767", name: "Dominica", categoryId: 3),
CountryCode(id: 64, code: "+1 809", name: "Dominican Republic", categoryId: 3),
]),
CountryCodeCategory(id: 4, name: "E", countries: [
CountryCode(id: 65, code: "+670", name: "East Timor", categoryId: 4),
CountryCode(id: 66, code: "+56", name: "Easter Island", categoryId: 4),
CountryCode(id: 67, code: "+593", name: "Ecuador", categoryId: 4),
CountryCode(id: 68, code: "+20", name: "Egypt", categoryId: 4),
CountryCode(id: 69, code: "+503", name: "El Salvador", categoryId: 4),
CountryCode(id: 70, code: "+240", name: "Equatorial Guinea", categoryId: 4),
CountryCode(id: 71, code: "+291", name: "Eritrea", categoryId: 4),
CountryCode(id: 72, code: "+372", name: "Estonia", categoryId: 4),
CountryCode(id: 73, code: "+251", name: "Ethiopia", categoryId: 4),
]),
CountryCodeCategory(id: 5, name: "F", countries: [
CountryCode(id: 74, code: "+500", name: "Falkland Islands", categoryId: 5),
CountryCode(id: 75, code: "+298", name: "Faroe Islands", categoryId: 5),
CountryCode(id: 76, code: "+679", name: "Fiji", categoryId: 5),
CountryCode(id: 77, code: "+358", name: "Finland", categoryId: 5),
CountryCode(id: 78, code: "+33", name: "France", categoryId: 5),
CountryCode(id: 79, code: "+596", name: "French Antilles", categoryId: 5),
CountryCode(id: 80, code: "+594", name: "French Guiana", categoryId: 5),
CountryCode(id: 81, code: "+689", name: "French Polynesia", categoryId: 5),
]),
CountryCodeCategory(id: 6, name: "G", countries: [
CountryCode(id: 82, code: "+241", name: "Gabon", categoryId: 6),
CountryCode(id: 83, code: "+220", name: "Gambia", categoryId: 6),
CountryCode(id: 84, code: "+995", name: "Georgia", categoryId: 6),
CountryCode(id: 85, code: "+49", name: "Germany", categoryId: 6),
CountryCode(id: 86, code: "+233", name: "Ghana", categoryId: 6),
CountryCode(id: 87, code: "+350", name: "Gibraltar", categoryId: 6),
CountryCode(id: 88, code: "+30", name: "Greece", categoryId: 6),
CountryCode(id: 89, code: "+299", name: "Greenland", categoryId: 6),
CountryCode(id: 90, code: "+1 473", name: "Grenada", categoryId: 6),
CountryCode(id: 91, code: "+590", name: "Guadeloupe", categoryId: 6),
CountryCode(id: 92, code: "+1 671", name: "Guam", categoryId: 6),
CountryCode(id: 93, code: "+502", name: "Guatemala", categoryId: 6),
CountryCode(id: 94, code: "+224", name: "Guinea", categoryId: 6),
CountryCode(id: 95, code: "+245", name: "Guinea-Bissau", categoryId: 6),
CountryCode(id: 96, code: "+595", name: "Guyana", categoryId: 6),
]),
CountryCodeCategory(id: 7, name: "H", countries: [
CountryCode(id: 97, code: "+509", name: "Haiti", categoryId: 7),
CountryCode(id: 98, code: "+504", name: "Honduras", categoryId: 7),
CountryCode(id: 99, code: "+852", name: "Hong Kong SAR China", categoryId: 7),
CountryCode(id: 100, code: "+36", name: "Hungary", categoryId: 7),
]),
CountryCodeCategory(id: 8, name: "I", countries: [
CountryCode(id: 101, code: "+354", name: "Iceland", categoryId: 8),
CountryCode(id: 102, code: "+91", name: "India", categoryId: 8),
CountryCode(id: 103, code: "+62", name: "Indonesia", categoryId: 8),
CountryCode(id: 104, code: "+98", name: "Iran", categoryId: 8),
CountryCode(id: 105, code: "+964", name: "Iraq", categoryId: 8),
CountryCode(id: 106, code: "+353", name: "Ireland", categoryId: 8),
CountryCode(id: 107, code: "+972", name: "Israel", categoryId: 8),
CountryCode(id: 108, code: "+39", name: "Italy", categoryId: 8),
CountryCode(id: 109, code: "+225", name: "Ivory Coast", categoryId: 8),
]),
CountryCodeCategory(id: 9, name: "J", countries: [
CountryCode(id: 110, code: "+1 876", name: "Jamaica", categoryId: 9),
CountryCode(id: 111, code: "+81", name: "Japan", categoryId: 9),
CountryCode(id: 112, code: "+962", name: "Jordan", categoryId: 9),
]),
CountryCodeCategory(id: 10, name: "K", countries: [
CountryCode(id: 113, code: "+7 7", name: "Kazakhstan", categoryId: 10),
CountryCode(id: 114, code: "+254", name: "Kenya", categoryId: 10),
CountryCode(id: 115, code: "+686", name: "Kiribati", categoryId: 10),
CountryCode(id: 116, code: "+965", name: "Kuwait", categoryId: 10),
CountryCode(id: 117, code: "+996", name: "Kyrgyzstan", categoryId: 10),
]),
CountryCodeCategory(id: 11, name: "L", countries: [
CountryCode(id: 118, code: "+856", name: "Laos", categoryId: 11),
CountryCode(id: 119, code: "+371", name: "Latvia", categoryId: 11),
CountryCode(id: 120, code: "+961", name: "Lebanon", categoryId: 11),
CountryCode(id: 121, code: "+266", name: "Lesotho", categoryId: 11),
CountryCode(id: 122, code: "+231", name: "Liberia", categoryId: 11),
CountryCode(id: 123, code: "+218", name: "Libya", categoryId: 11),
CountryCode(id: 124, code: "+423", name: "Liechtenstein", categoryId: 11),
CountryCode(id: 125, code: "+370", name: "Lithuania", categoryId: 11),
CountryCode(id: 126, code: "+352", name: "Luxembourg", categoryId: 11),
]),
CountryCodeCategory(id: 12, name: "M", countries: [
CountryCode(id: 127, code: "+853", name: "Macau SAR China", categoryId: 12),
CountryCode(id: 128, code: "+389", name: "Macedonia", categoryId: 12),
CountryCode(id: 129, code: "+261", name: "Madagascar", categoryId: 12),
CountryCode(id: 130, code: "+265", name: "Malawi", categoryId: 12),
CountryCode(id: 131, code: "+60", name: "Malaysia", categoryId: 12),
CountryCode(id: 132, code: "+960", name: "Maldives", categoryId: 12),
CountryCode(id: 133, code: "+223", name: "Mali", categoryId: 12),
CountryCode(id: 134, code: "+356", name: "Malta", categoryId: 12),
CountryCode(id: 135, code: "+692", name: "Marshall Islands", categoryId: 12),
CountryCode(id: 136, code: "+596", name: "Martinique", categoryId: 12),
CountryCode(id: 137, code: "+222", name: "Mauritania", categoryId: 12),
CountryCode(id: 138, code: "+230", name: "Mauritius", categoryId: 12),
CountryCode(id: 139, code: "+262", name: "Mayotte", categoryId: 12),
CountryCode(id: 140, code: "+52", name: "Mexico", categoryId: 12),
CountryCode(id: 141, code: "+691", name: "Micronesia", categoryId: 12),
CountryCode(id: 142, code: "+1 808", name: "Midway Island", categoryId: 12),
CountryCode(id: 143, code: "+373", name: "Moldova", categoryId: 12),
CountryCode(id: 144, code: "+377", name: "Monaco", categoryId: 12),
CountryCode(id: 145, code: "+976", name: "Mongolia", categoryId: 12),
CountryCode(id: 146, code: "+382", name: "Montenegro", categoryId: 12),
CountryCode(id: 147, code: "+1664", name: "Montserrat", categoryId: 12),
CountryCode(id: 148, code: "+212", name: "Morocco", categoryId: 12),
CountryCode(id: 149, code: "+95", name: "Myanmar", categoryId: 12),
]),
CountryCodeCategory(id: 13, name: "N", countries: [
CountryCode(id: 150, code: "+264", name: "Namibia", categoryId: 13),
CountryCode(id: 151, code: "+674", name: "Nauru", categoryId: 13),
CountryCode(id: 152, code: "+977", name: "Nepal", categoryId: 13),
CountryCode(id: 153, code: "+31", name: "Netherlands", categoryId: 13),
CountryCode(id: 154, code: "+599", name: "Netherlands Antilles", categoryId: 13),
CountryCode(id: 155, code: "+1 869", name: "Nevis", categoryId: 13),
CountryCode(id: 156, code: "+687", name: "New Caledonia", categoryId: 13),
CountryCode(id: 157, code: "+64", name: "New Zealand", categoryId: 13),
CountryCode(id: 158, code: "+505", name: "Nicaragua", categoryId: 13),
CountryCode(id: 159, code: "+227", name: "Niger", categoryId: 13),
CountryCode(id: 160, code: "+234", name: "Nigeria", categoryId: 13),
CountryCode(id: 161, code: "+683", name: "Niue", categoryId: 13),
CountryCode(id: 162, code: "+672", name: "Norfolk Island", categoryId: 13),
CountryCode(id: 163, code: "+850", name: "North Korea", categoryId: 13),
CountryCode(id: 164, code: "+1 670", name: "Northern Mariana Islands", categoryId: 13),
CountryCode(id: 165, code: "+47", name: "Norway", categoryId: 13),
]),
CountryCodeCategory(id: 14, name: "O", countries: [
CountryCode(id: 166, code: "+968", name: "Oman", categoryId: 14),
]),
CountryCodeCategory(id: 15, name: "P", countries: [
CountryCode(id: 167, code: "+92", name: "Pakistan", categoryId: 15),
CountryCode(id: 168, code: "+680", name: "Palau", categoryId: 15),
CountryCode(id: 169, code: "+970", name: "Palestinian Territory", categoryId: 15),
CountryCode(id: 170, code: "+507", name: "Panama", categoryId: 15),
CountryCode(id: 171, code: "+675", name: "Papua New Guinea", categoryId: 15),
CountryCode(id: 172, code: "+595", name: "Paraguay", categoryId: 15),
CountryCode(id: 173, code: "+51", name: "Peru", categoryId: 15),
CountryCode(id: 174, code: "+63", name: "Philippines", categoryId: 15),
CountryCode(id: 175, code: "+48", name: "Poland", categoryId: 15),
CountryCode(id: 176, code: "+351", name: "Portugal", categoryId: 15),
CountryCode(id: 177, code: "+1 787", name: "Puerto Rico", categoryId: 15),
]),
CountryCodeCategory(id: 16, name: "Q", countries: [
CountryCode(id: 178, code: "+974", name: "Qatar", categoryId: 16),
]),
CountryCodeCategory(id: 17, name: "R", countries: [
CountryCode(id: 179, code: "+262", name: "Reunion", categoryId: 17),
CountryCode(id: 180, code: "+40", name: "Romania", categoryId: 17),
CountryCode(id: 181, code: "+7", name: "Russia", categoryId: 17),
CountryCode(id: 182, code: "+250", name: "Rwanda", categoryId: 17),
]),
CountryCodeCategory(id: 18, name: "S", countries: [
CountryCode(id: 183, code: "+685", name: "Samoa", categoryId: 18),
CountryCode(id: 184, code: "+378", name: "San Marino", categoryId: 18),
CountryCode(id: 185, code: "+966", name: "Saudi Arabia", categoryId: 18),
CountryCode(id: 186, code: "+221", name: "Senegal", categoryId: 18),
CountryCode(id: 187, code: "+381", name: "Serbia", categoryId: 18),
CountryCode(id: 188, code: "+248", name: "Seychelles", categoryId: 18),
CountryCode(id: 189, code: "+232", name: "Sierra Leone", categoryId: 18),
CountryCode(id: 190, code: "+65", name: "Singapore", categoryId: 18),
CountryCode(id: 191, code: "+421", name: "Slovakia", categoryId: 18),
CountryCode(id: 192, code: "+386", name: "Slovenia", categoryId: 18),
CountryCode(id: 193, code: "+677", name: "Solomon Islands", categoryId: 18),
CountryCode(id: 194, code: "+27", name: "South Africa", categoryId: 18),
CountryCode(id: 195, code: "+500", name: "South Georgia and the South Sandwich Islands", categoryId: 18),
CountryCode(id: 196, code: "+82", name: "South Korea", categoryId: 18),
CountryCode(id: 197, code: "+34", name: "Spain", categoryId: 18),
CountryCode(id: 198, code: "+94", name: "Sri Lanka", categoryId: 18),
CountryCode(id: 199, code: "+249", name: "Sudan", categoryId: 18),
CountryCode(id: 200, code: "+597", name: "Suriname", categoryId: 18),
CountryCode(id: 201, code: "+268", name: "Swaziland", categoryId: 18),
CountryCode(id: 202, code: "+46", name: "Sweden", categoryId: 18),
CountryCode(id: 203, code: "+41", name: "Switzerland", categoryId: 18),
CountryCode(id: 204, code: "+963", name: "Syria", categoryId: 18),
]),
CountryCodeCategory(id: 19, name: "T", countries: [
CountryCode(id: 205, code: "+886", name: "Taiwan", categoryId: 19),
CountryCode(id: 206, code: "+992", name: "Tajikistan", categoryId: 19),
CountryCode(id: 207, code: "+255", name: "Tanzania", categoryId: 19),
CountryCode(id: 208, code: "+66", name: "Thailand", categoryId: 19),
CountryCode(id: 209, code: "+670", name: "Timor Leste", categoryId: 19),
CountryCode(id: 210, code: "+228", name: "Togo", categoryId: 19),
CountryCode(id: 211, code: "+690", name: "Tokelau", categoryId: 19),
CountryCode(id: 212, code: "+676", name: "Tonga", categoryId: 19),
CountryCode(id: 213, code: "+1 868", name: "Trinidad and Tobago", categoryId: 19),
CountryCode(id: 214, code: "+216", name: "Tunisia", categoryId: 19),
CountryCode(id: 215, code: "+90", name: "Turkey", categoryId: 19),
CountryCode(id: 216, code: "+993", name: "Turkmenistan", categoryId: 19),
CountryCode(id: 217, code: "+1 649", name: "Turks and Caicos Islands", categoryId: 19),
CountryCode(id: 218, code: "+688", name: "Tuvalu", categoryId: 19),
]),
CountryCodeCategory(id: 20, name: "U", countries: [
CountryCode(id: 219, code: "+1 340", name: "U.S. Virgin Islands", categoryId: 20),
CountryCode(id: 220, code: "+256", name: "Uganda", categoryId: 20),
CountryCode(id: 221, code: "+380", name: "Ukraine", categoryId: 20),
CountryCode(id: 222, code: "+971", name: "United Arab Emirates", categoryId: 20),
CountryCode(id: 223, code: "+44", name: "United Kingdom", categoryId: 20),
CountryCode(id: 224, code: "+1", name: "United States", categoryId: 20),
CountryCode(id: 225, code: "+598", name: "Uruguay", categoryId: 20),
CountryCode(id: 226, code: "+998", name: "Uzbekistan", categoryId: 20),
]),
CountryCodeCategory(id: 21, name: "V", countries: [
CountryCode(id: 227, code: "+678", name: "Vanuatu", categoryId: 21),
CountryCode(id: 228, code: "+58", name: "Venezuela", categoryId: 21),
CountryCode(id: 229, code: "+84", name: "Vietnam", categoryId: 21),
]),
CountryCodeCategory(id: 22, name: "W", countries: [
CountryCode(id: 230, code: "+1 808", name: "Wake Island", categoryId: 22),
CountryCode(id: 231, code: "+681", name: "Wallis and Futuna", categoryId: 22),
]),
CountryCodeCategory(id: 23, name: "Y", countries: [
CountryCode(id: 232, code: "+967", name: "Yemen", categoryId: 23)
]),
CountryCodeCategory(id: 24, name: "Z", countries: [
CountryCode(id: 233, code: "+260", name: "Zambia", categoryId: 24),
CountryCode(id: 234, code: "+255", name: "Zanzibar", categoryId: 24),
CountryCode(id: 235, code: "+263", name: "Zimbabwe", categoryId: 24)
]),
]
Thanks to #Sai kumar Reddy,
here's a piece of python (<= 3.6) code which generates a swift struct and writes to file with country-name, dial-code and code.
file = open("CountryCodes.swift", "x")
file.write("import Foundation\n\n")
file.write("struct CountryCode {\n")
file.write("\tvar name: String\n")
file.write("\tvar dialCode: String\n")
file.write("\tvar code: String\n")
file.write("}\n\n")
file.write("var countryCodes: [CountryCode] = [\n")
codes = [ { "name": "Afghanistan", "dial_code": "+93", "code": "AF" }, { "name": "Åland Islands", "dial_code": "+358", "code": "AX" }, { "name": "Albania", "dial_code": "+355", "code": "AL" }, { "name": "Algeria", "dial_code": "+213", "code": "DZ" }, { "name": "American Samoa", "dial_code": "+1684", "code": "AS" }, { "name": "Andorra", "dial_code": "+376", "code": "AD" }, { "name": "Angola", "dial_code": "+244", "code": "AO" }, { "name": "Anguilla", "dial_code": "+1264", "code": "AI" }, { "name": "Antarctica", "dial_code": "+672", "code": "AQ" }, { "name": "Antigua and Barbuda", "dial_code": "+1268", "code": "AG" }, { "name": "Argentina", "dial_code": "+54", "code": "AR" }, { "name": "Armenia", "dial_code": "+374", "code": "AM" }, { "name": "Aruba", "dial_code": "+297", "code": "AW" }, { "name": "Australia", "dial_code": "+61", "code": "AU" }, { "name": "Austria", "dial_code": "+43", "code": "AT" }, { "name": "Azerbaijan", "dial_code": "+994", "code": "AZ" }, { "name": "Bahamas", "dial_code": "+1242", "code": "BS" }, { "name": "Bahrain", "dial_code": "+973", "code": "BH" }, { "name": "Bangladesh", "dial_code": "+880", "code": "BD" }, { "name": "Barbados", "dial_code": "+1246", "code": "BB" }, { "name": "Belarus", "dial_code": "+375", "code": "BY" }, { "name": "Belgium", "dial_code": "+32", "code": "BE" }, { "name": "Belize", "dial_code": "+501", "code": "BZ" }, { "name": "Benin", "dial_code": "+229", "code": "BJ" }, { "name": "Bermuda", "dial_code": "+1441", "code": "BM" }, { "name": "Bhutan", "dial_code": "+975", "code": "BT" }, { "name": "Bolivia, Plurinational State of bolivia", "dial_code": "+591", "code": "BO" }, { "name": "Bosnia and Herzegovina", "dial_code": "+387", "code": "BA" }, { "name": "Botswana", "dial_code": "+267", "code": "BW" }, { "name": "Bouvet Island", "dial_code": "+47", "code": "BV" }, { "name": "Brazil", "dial_code": "+55", "code": "BR" }, { "name": "British Indian Ocean Territory", "dial_code": "+246", "code": "IO" }, { "name": "Brunei Darussalam", "dial_code": "+673", "code": "BN" }, { "name": "Bulgaria", "dial_code": "+359", "code": "BG" }, { "name": "Burkina Faso", "dial_code": "+226", "code": "BF" }, { "name": "Burundi", "dial_code": "+257", "code": "BI" }, { "name": "Cambodia", "dial_code": "+855", "code": "KH" }, { "name": "Cameroon", "dial_code": "+237", "code": "CM" }, { "name": "Canada", "dial_code": "+1", "code": "CA" }, { "name": "Cape Verde", "dial_code": "+238", "code": "CV" }, { "name": "Cayman Islands", "dial_code": "+ 345", "code": "KY" }, { "name": "Central African Republic", "dial_code": "+236", "code": "CF" }, { "name": "Chad", "dial_code": "+235", "code": "TD" }, { "name": "Chile", "dial_code": "+56", "code": "CL" }, { "name": "China", "dial_code": "+86", "code": "CN" }, { "name": "Christmas Island", "dial_code": "+61", "code": "CX" }, { "name": "Cocos (Keeling) Islands", "dial_code": "+61", "code": "CC" }, { "name": "Colombia", "dial_code": "+57", "code": "CO" }, { "name": "Comoros", "dial_code": "+269", "code": "KM" }, { "name": "Congo", "dial_code": "+242", "code": "CG" }, { "name": "Congo, The Democratic Republic of the Congo", "dial_code": "+243", "code": "CD" }, { "name": "Cook Islands", "dial_code": "+682", "code": "CK" }, { "name": "Costa Rica", "dial_code": "+506", "code": "CR" }, { "name": "Cote d'Ivoire", "dial_code": "+225", "code": "CI" }, { "name": "Croatia", "dial_code": "+385", "code": "HR" }, { "name": "Cuba", "dial_code": "+53", "code": "CU" }, { "name": "Cyprus", "dial_code": "+357", "code": "CY" }, { "name": "Czech Republic", "dial_code": "+420", "code": "CZ" }, { "name": "Denmark", "dial_code": "+45", "code": "DK" }, { "name": "Djibouti", "dial_code": "+253", "code": "DJ" }, { "name": "Dominica", "dial_code": "+1767", "code": "DM" }, { "name": "Dominican Republic", "dial_code": "+1849", "code": "DO" }, { "name": "Ecuador", "dial_code": "+593", "code": "EC" }, { "name": "Egypt", "dial_code": "+20", "code": "EG" }, { "name": "El Salvador", "dial_code": "+503", "code": "SV" }, { "name": "Equatorial Guinea", "dial_code": "+240", "code": "GQ" }, { "name": "Eritrea", "dial_code": "+291", "code": "ER" }, { "name": "Estonia", "dial_code": "+372", "code": "EE" }, { "name": "Ethiopia", "dial_code": "+251", "code": "ET" }, { "name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK" }, { "name": "Faroe Islands", "dial_code": "+298", "code": "FO" }, { "name": "Fiji", "dial_code": "+679", "code": "FJ" }, { "name": "Finland", "dial_code": "+358", "code": "FI" }, { "name": "France", "dial_code": "+33", "code": "FR" }, { "name": "French Guiana", "dial_code": "+594", "code": "GF" }, { "name": "French Polynesia", "dial_code": "+689", "code": "PF" }, { "name": "French Southern Territories", "dial_code": "+262", "code": "TF" }, { "name": "Gabon", "dial_code": "+241", "code": "GA" }, { "name": "Gambia", "dial_code": "+220", "code": "GM" }, { "name": "Georgia", "dial_code": "+995", "code": "GE" }, { "name": "Germany", "dial_code": "+49", "code": "DE" }, { "name": "Ghana", "dial_code": "+233", "code": "GH" }, { "name": "Gibraltar", "dial_code": "+350", "code": "GI" }, { "name": "Greece", "dial_code": "+30", "code": "GR" }, { "name": "Greenland", "dial_code": "+299", "code": "GL" }, { "name": "Grenada", "dial_code": "+1473", "code": "GD" }, { "name": "Guadeloupe", "dial_code": "+590", "code": "GP" }, { "name": "Guam", "dial_code": "+1671", "code": "GU" }, { "name": "Guatemala", "dial_code": "+502", "code": "GT" }, { "name": "Guernsey", "dial_code": "+44", "code": "GG" }, { "name": "Guinea", "dial_code": "+224", "code": "GN" }, { "name": "Guinea-Bissau", "dial_code": "+245", "code": "GW" }, { "name": "Guyana", "dial_code": "+592", "code": "GY" }, { "name": "Haiti", "dial_code": "+509", "code": "HT" }, { "name": "Heard Island and Mcdonald Islands", "dial_code": "+0", "code": "HM" }, { "name": "Holy See (Vatican City State)", "dial_code": "+379", "code": "VA" }, { "name": "Honduras", "dial_code": "+504", "code": "HN" }, { "name": "Hong Kong", "dial_code": "+852", "code": "HK" }, { "name": "Hungary", "dial_code": "+36", "code": "HU" }, { "name": "Iceland", "dial_code": "+354", "code": "IS" }, { "name": "India", "dial_code": "+91", "code": "IN" }, { "name": "Indonesia", "dial_code": "+62", "code": "ID" }, { "name": "Iran, Islamic Republic of Persian Gulf", "dial_code": "+98", "code": "IR" }, { "name": "Iraq", "dial_code": "+964", "code": "IQ" }, { "name": "Ireland", "dial_code": "+353", "code": "IE" }, { "name": "Isle of Man", "dial_code": "+44", "code": "IM" }, { "name": "Israel", "dial_code": "+972", "code": "IL" }, { "name": "Italy", "dial_code": "+39", "code": "IT" }, { "name": "Jamaica", "dial_code": "+1876", "code": "JM" }, { "name": "Japan", "dial_code": "+81", "code": "JP" }, { "name": "Jersey", "dial_code": "+44", "code": "JE" }, { "name": "Jordan", "dial_code": "+962", "code": "JO" }, { "name": "Kazakhstan", "dial_code": "+7", "code": "KZ" }, { "name": "Kenya", "dial_code": "+254", "code": "KE" }, { "name": "Kiribati", "dial_code": "+686", "code": "KI" }, { "name": "Korea, Democratic People's Republic of Korea", "dial_code": "+850", "code": "KP" }, { "name": "Korea, Republic of South Korea", "dial_code": "+82", "code": "KR" }, { "name": "Kosovo", "dial_code": "+383", "code": "XK" }, { "name": "Kuwait", "dial_code": "+965", "code": "KW" }, { "name": "Kyrgyzstan", "dial_code": "+996", "code": "KG" }, { "name": "Laos", "dial_code": "+856", "code": "LA" }, { "name": "Latvia", "dial_code": "+371", "code": "LV" }, { "name": "Lebanon", "dial_code": "+961", "code": "LB" }, { "name": "Lesotho", "dial_code": "+266", "code": "LS" }, { "name": "Liberia", "dial_code": "+231", "code": "LR" }, { "name": "Libyan Arab Jamahiriya", "dial_code": "+218", "code": "LY" }, { "name": "Liechtenstein", "dial_code": "+423", "code": "LI" }, { "name": "Lithuania", "dial_code": "+370", "code": "LT" }, { "name": "Luxembourg", "dial_code": "+352", "code": "LU" }, { "name": "Macao", "dial_code": "+853", "code": "MO" }, { "name": "Macedonia", "dial_code": "+389", "code": "MK" }, { "name": "Madagascar", "dial_code": "+261", "code": "MG" }, { "name": "Malawi", "dial_code": "+265", "code": "MW" }, { "name": "Malaysia", "dial_code": "+60", "code": "MY" }, { "name": "Maldives", "dial_code": "+960", "code": "MV" }, { "name": "Mali", "dial_code": "+223", "code": "ML" }, { "name": "Malta", "dial_code": "+356", "code": "MT" }, { "name": "Marshall Islands", "dial_code": "+692", "code": "MH" }, { "name": "Martinique", "dial_code": "+596", "code": "MQ" }, { "name": "Mauritania", "dial_code": "+222", "code": "MR" }, { "name": "Mauritius", "dial_code": "+230", "code": "MU" }, { "name": "Mayotte", "dial_code": "+262", "code": "YT" }, { "name": "Mexico", "dial_code": "+52", "code": "MX" }, { "name": "Micronesia, Federated States of Micronesia", "dial_code": "+691", "code": "FM" }, { "name": "Moldova", "dial_code": "+373", "code": "MD" }, { "name": "Monaco", "dial_code": "+377", "code": "MC" }, { "name": "Mongolia", "dial_code": "+976", "code": "MN" }, { "name": "Montenegro", "dial_code": "+382", "code": "ME" }, { "name": "Montserrat", "dial_code": "+1664", "code": "MS" }, { "name": "Morocco", "dial_code": "+212", "code": "MA" }, { "name": "Mozambique", "dial_code": "+258", "code": "MZ" }, { "name": "Myanmar", "dial_code": "+95", "code": "MM" }, { "name": "Namibia", "dial_code": "+264", "code": "NA" }, { "name": "Nauru", "dial_code": "+674", "code": "NR" }, { "name": "Nepal", "dial_code": "+977", "code": "NP" }, { "name": "Netherlands", "dial_code": "+31", "code": "NL" }, { "name": "Netherlands Antilles", "dial_code": "+599", "code": "AN" }, { "name": "New Caledonia", "dial_code": "+687", "code": "NC" }, { "name": "New Zealand", "dial_code": "+64", "code": "NZ" }, { "name": "Nicaragua", "dial_code": "+505", "code": "NI" }, { "name": "Niger", "dial_code": "+227", "code": "NE" }, { "name": "Nigeria", "dial_code": "+234", "code": "NG" }, { "name": "Niue", "dial_code": "+683", "code": "NU" }, { "name": "Norfolk Island", "dial_code": "+672", "code": "NF" }, { "name": "Northern Mariana Islands", "dial_code": "+1670", "code": "MP" }, { "name": "Norway", "dial_code": "+47", "code": "NO" }, { "name": "Oman", "dial_code": "+968", "code": "OM" }, { "name": "Pakistan", "dial_code": "+92", "code": "PK" }, { "name": "Palau", "dial_code": "+680", "code": "PW" }, { "name": "Palestinian Territory, Occupied", "dial_code": "+970", "code": "PS" }, { "name": "Panama", "dial_code": "+507", "code": "PA" }, { "name": "Papua New Guinea", "dial_code": "+675", "code": "PG" }, { "name": "Paraguay", "dial_code": "+595", "code": "PY" }, { "name": "Peru", "dial_code": "+51", "code": "PE" }, { "name": "Philippines", "dial_code": "+63", "code": "PH" }, { "name": "Pitcairn", "dial_code": "+64", "code": "PN" }, { "name": "Poland", "dial_code": "+48", "code": "PL" }, { "name": "Portugal", "dial_code": "+351", "code": "PT" }, { "name": "Puerto Rico", "dial_code": "+1939", "code": "PR" }, { "name": "Qatar", "dial_code": "+974", "code": "QA" }, { "name": "Romania", "dial_code": "+40", "code": "RO" }, { "name": "Russia", "dial_code": "+7", "code": "RU" }, { "name": "Rwanda", "dial_code": "+250", "code": "RW" }, { "name": "Reunion", "dial_code": "+262", "code": "RE" }, { "name": "Saint Barthelemy", "dial_code": "+590", "code": "BL" }, { "name": "Saint Helena, Ascension and Tristan Da Cunha", "dial_code": "+290", "code": "SH" }, { "name": "Saint Kitts and Nevis", "dial_code": "+1869", "code": "KN" }, { "name": "Saint Lucia", "dial_code": "+1758", "code": "LC" }, { "name": "Saint Martin", "dial_code": "+590", "code": "MF" }, { "name": "Saint Pierre and Miquelon", "dial_code": "+508", "code": "PM" }, { "name": "Saint Vincent and the Grenadines", "dial_code": "+1784", "code": "VC" }, { "name": "Samoa", "dial_code": "+685", "code": "WS" }, { "name": "San Marino", "dial_code": "+378", "code": "SM" }, { "name": "Sao Tome and Principe", "dial_code": "+239", "code": "ST" }, { "name": "Saudi Arabia", "dial_code": "+966", "code": "SA" }, { "name": "Senegal", "dial_code": "+221", "code": "SN" }, { "name": "Serbia", "dial_code": "+381", "code": "RS" }, { "name": "Seychelles", "dial_code": "+248", "code": "SC" }, { "name": "Sierra Leone", "dial_code": "+232", "code": "SL" }, { "name": "Singapore", "dial_code": "+65", "code": "SG" }, { "name": "Slovakia", "dial_code": "+421", "code": "SK" }, { "name": "Slovenia", "dial_code": "+386", "code": "SI" }, { "name": "Solomon Islands", "dial_code": "+677", "code": "SB" }, { "name": "Somalia", "dial_code": "+252", "code": "SO" }, { "name": "South Africa", "dial_code": "+27", "code": "ZA" }, { "name": "South Sudan", "dial_code": "+211", "code": "SS" }, { "name": "South Georgia and the South Sandwich Islands", "dial_code": "+500", "code": "GS" }, { "name": "Spain", "dial_code": "+34", "code": "ES" }, { "name": "Sri Lanka", "dial_code": "+94", "code": "LK" }, { "name": "Sudan", "dial_code": "+249", "code": "SD" }, { "name": "Suriname", "dial_code": "+597", "code": "SR" }, { "name": "Svalbard and Jan Mayen", "dial_code": "+47", "code": "SJ" }, { "name": "Swaziland", "dial_code": "+268", "code": "SZ" }, { "name": "Sweden", "dial_code": "+46", "code": "SE" }, { "name": "Switzerland", "dial_code": "+41", "code": "CH" }, { "name": "Syrian Arab Republic", "dial_code": "+963", "code": "SY" }, { "name": "Taiwan", "dial_code": "+886", "code": "TW" }, { "name": "Tajikistan", "dial_code": "+992", "code": "TJ" }, { "name": "Tanzania, United Republic of Tanzania", "dial_code": "+255", "code": "TZ" }, { "name": "Thailand", "dial_code": "+66", "code": "TH" }, { "name": "Timor-Leste", "dial_code": "+670", "code": "TL" }, { "name": "Togo", "dial_code": "+228", "code": "TG" }, { "name": "Tokelau", "dial_code": "+690", "code": "TK" }, { "name": "Tonga", "dial_code": "+676", "code": "TO" }, { "name": "Trinidad and Tobago", "dial_code": "+1868", "code": "TT" }, { "name": "Tunisia", "dial_code": "+216", "code": "TN" }, { "name": "Turkey", "dial_code": "+90", "code": "TR" }, { "name": "Turkmenistan", "dial_code": "+993", "code": "TM" }, { "name": "Turks and Caicos Islands", "dial_code": "+1649", "code": "TC" }, { "name": "Tuvalu", "dial_code": "+688", "code": "TV" }, { "name": "Uganda", "dial_code": "+256", "code": "UG" }, { "name": "Ukraine", "dial_code": "+380", "code": "UA" }, { "name": "United Arab Emirates", "dial_code": "+971", "code": "AE" }, { "name": "United Kingdom", "dial_code": "+44", "code": "GB" }, { "name": "United States", "dial_code": "+1", "code": "US" }, { "name": "Uruguay", "dial_code": "+598", "code": "UY" }, { "name": "Uzbekistan", "dial_code": "+998", "code": "UZ" }, { "name": "Vanuatu", "dial_code": "+678", "code": "VU" }, { "name": "Venezuela, Bolivarian Republic of Venezuela", "dial_code": "+58", "code": "VE" }, { "name": "Vietnam", "dial_code": "+84", "code": "VN" }, { "name": "Virgin Islands, British", "dial_code": "+1284", "code": "VG" }, { "name": "Virgin Islands, U.S.", "dial_code": "+1340", "code": "VI" }, { "name": "Wallis and Futuna", "dial_code": "+681", "code": "WF" }, { "name": "Yemen", "dial_code": "+967", "code": "YE" }, { "name": "Zambia", "dial_code": "+260", "code": "ZM" }, { "name": "Zimbabwe", "dial_code": "+263", "code": "ZW" } ]
for code in codes:
file.write("\tCountryCode(name: \"{}\", dialCode: \"{}\", code: \"{}\"),\n".format(code.get("name"), code.get("dial_code"), code.get("code")))
file.write("]\n")
file.close()
Just run in the terminal this command:
$ python3.6 file.py
I have tried to created a simpler version of the answer by Raj Joshi.
class CountryCodes {
struct CountryWithCode {
var countryCode: String
var countryName: String
var dialCode: String
}
private static let countryDictionary = ["AF":"93", "AL":"355", "DZ":"213","AS":"1", "AD":"376", "AO":"244", "AI":"1","AG":"1","AR":"54","AM":"374","AW":"297","AU":"61","AT":"43","AZ":"994","BS":"1","BH":"973","BD":"880","BB":"1","BY":"375","BE":"32","BZ":"501","BJ":"229","BM":"1","BT":"975","BA":"387","BW":"267","BR":"55","IO":"246","BG":"359","BF":"226","BI":"257","KH":"855","CM":"237","CA":"1","CV":"238","KY":"345","CF":"236","TD":"235","CL":"56","CN":"86","CX":"61","CO":"57","KM":"269","CG":"242","CK":"682","CR":"506","HR":"385","CU":"53","CY":"537","CZ":"420","DK":"45","DJ":"253","DM":"1","DO":"1","EC":"593","EG":"20","SV":"503","GQ":"240","ER":"291","EE":"372","ET":"251","FO":"298","FJ":"679","FI":"358","FR":"33","GF":"594","PF":"689","GA":"241","GM":"220","GE":"995","DE":"49","GH":"233","GI":"350","GR":"30","GL":"299","GD":"1","GP":"590","GU":"1","GT":"502","GN":"224","GW":"245","GY":"595","HT":"509","HN":"504","HU":"36","IS":"354","IN":"91","ID":"62","IQ":"964","IE":"353","IL":"972","IT":"39","JM":"1","JP":"81","JO":"962","KZ":"77","KE":"254","KI":"686","KW":"965","KG":"996","LV":"371","LB":"961","LS":"266","LR":"231","LI":"423","LT":"370","LU":"352","MG":"261","MW":"265","MY":"60","MV":"960","ML":"223","MT":"356","MH":"692","MQ":"596","MR":"222","MU":"230","YT":"262","MX":"52","MC":"377","MN":"976","ME":"382","MS":"1","MA":"212","MM":"95","NA":"264","NR":"674","NP":"977","NL":"31","AN":"599","NC":"687","NZ":"64","NI":"505","NE":"227","NG":"234","NU":"683","NF":"672","MP":"1","NO":"47","OM":"968","PK":"92","PW":"680","PA":"507","PG":"675","PY":"595","PE":"51","PH":"63","PL":"48","PT":"351","PR":"1","QA":"974","RO":"40","RW":"250","WS":"685","SM":"378","SA":"966","SN":"221","RS":"381","SC":"248","SL":"232","SG":"65","SK":"421","SI":"386","SB":"677","ZA":"27","GS":"500","ES":"34","LK":"94","SD":"249","SR":"597","SZ":"268","SE":"46","CH":"41","TJ":"992","TH":"66","TG":"228","TK":"690","TO":"676","TT":"1","TN":"216","TR":"90","TM":"993","TC":"1","TV":"688","UG":"256","UA":"380","AE":"971","GB":"44","US":"1", "UY":"598","UZ":"998", "VU":"678", "WF":"681","YE":"967","ZM":"260","ZW":"263","BO":"591","BN":"673","CC":"61","CD":"243","CI":"225","FK":"500","GG":"44","VA":"379","HK":"852","IR":"98","IM":"44","JE":"44","KP":"850","KR":"82","LA":"856","LY":"218","MO":"853","MK":"389","FM":"691","MD":"373","MZ":"258","PS":"970","PN":"872","RE":"262","RU":"7","BL":"590","SH":"290","KN":"1","LC":"1","MF":"590","PM":"508","VC":"1","ST":"239","SO":"252","SJ":"47","SY":"963","TW":"886","TZ":"255","TL":"670","VE":"58","VN":"84","VG":"284","VI":"340"]
static func values() -> [CountryWithCode] {
var countriesWithCode = [CountryWithCode]()
let countryCodes = countryDictionary.keys
for countryCode in countryCodes {
let countryName = Locale.current.localizedString(forRegionCode: countryCode) ?? "N/A"
let dialCode = countryDictionary[countryCode] ?? "N/A"
let countryValue = CountryWithCode(countryCode: countryCode,
countryName: countryName,
dialCode: dialCode)
countriesWithCode.append(countryValue)
}
let sortedCountries = countriesWithCode.sorted { (firstCountry, secondCountry) -> Bool in
let sortedByName = firstCountry.countryName.compare(secondCountry.countryName) == .orderedAscending
return sortedByName
}
countriesWithCode.removeAll()
countriesWithCode.append(contentsOf: sortedCountries)
return countriesWithCode
}
}
The above code can be implemented as:
let countryCodes = CountryCodes.values()
print(countryCodes.first?.dialCode)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
{
"status": 200,
"message": "Success!",
"result": {
"LessonDetail": [
{
"id": 78,
"lessonjs": "<script src=\"https://learnspeakthai.com/js/lesson.js\" ></script>",
"name": "Question words #3: What?",
"code": "ST1C2L026",
"chapter_id": "12",
"sort_order": "25",
"content_top": "",
"image": "https://learnspeakthai.com/uploads/images/lesson/lesson_thumb/8b2cbbca4a711009806b915971478cb54b2ab0d1.jpg",
"show_tone_practice": "0",
"tone_practice_shown": "None",
"tone_practise_data": "",
"show_slideshow": "1",
"active": "1",
"created_at": "2011-07-28T02:51:34.000000Z",
"updated_at": "2014-10-24T20:24:17.000000Z",
"pdf": "",
"is_practise_data": 0
}
],
"SubLesson": [
{
"id": 86,
"name": "Question words 3: What?",
"show_name": "0",
"code": "ST1C2L027",
"lesson_id": "78",
"sort_order": "5",
"content_top": "‘³A-ry?’ = ‘what?’ It is always used at the end of sentence.",
"slide": [
{
"id": 321,
"sub_lesson_id": "86",
"code": "ST1C2L028",
"isaana": "³A-ry",
"thai": "อะไร",
"english": "What? ",
"english_word_order": "",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/34322cde0baa04df7ed58295863e390c7a489a98.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/ff791dbc630a4407eec2d4bdb4cbf677fac820bb.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/ed99dca146d83b40c8a91b1a2cc58844fa9d8162.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/5ca41fb350d2713194b00071fab749d36d376f8c.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:55:06.000000Z",
"updated_at": "2011-07-28T02:55:21.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 322,
"sub_lesson_id": "86",
"code": "ST1C2L029",
"isaana": "(Kun) cªheu ³a-ry?",
"thai": "คุณชื่ออะไร",
"english": "What’s your name?",
"english_word_order": "(You name what?)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/fff77db9e63b1ed203ef186c1252dee9ee47f1e6.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/85315f3e7892fdefff80dbc17a140fed7a1a0812.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/158079fe8d6aab8d95201d2c945a378b971a5e04.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/d9f7c4170a13336b95846b995add06f3537e6730.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:56:23.000000Z",
"updated_at": "2011-08-19T00:20:38.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 323,
"sub_lesson_id": "86",
"code": "ST1C2L030",
"isaana": "Cªheu B°orb",
"thai": "ชื่อบ๊อบ",
"english": "My name is Bob ",
"english_word_order": "(Name Bob)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/783d893e197d718c9d32624cf6aa6eff25113dc2.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/fae572b408441871d16d9335675f88895c533f4e.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/7b80d533c30f9d7839a1cd5f058c10092960dcf8.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/57ce04c653580cdf525af9b49d8deb19f49c9786.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:58:00.000000Z",
"updated_at": "2011-07-28T02:58:17.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 324,
"sub_lesson_id": "86",
"code": "ST1C2L031",
"isaana": "An-n°ee r§iak w§ah ³a-ry?",
"thai": "อันนี้เรียกว่าอะไร",
"english": "What’s this called?",
"english_word_order": "(This called what?)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/8244e536e5bcd1f0383b322f0df04a31926888f2.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/0c31968d79a921bf8b2810d8b05b9d01c4f6898f.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/394021ec2ff89c15a607ce3fd31ba0835115b84a.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/9034801d15fb058ea4a2bc0ba545e92cc3ec63a2.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:59:24.000000Z",
"updated_at": "2011-07-28T03:00:02.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 325,
"sub_lesson_id": "86",
"code": "ST1C2L032",
"isaana": " R§iak w§ah d§ton °my ",
"thai": " เรียกว่าต้นไม้ ",
"english": "It’s called a tree",
"english_word_order": "",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/2725e831aaf141324cc62dc61300b95dd544d487.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/b95be383542085e2c3ef1500c86c7c432c8155f9.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/e66433b0437f6b1b6d0f65b61c8b13b4e27fd57d.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/88b3abbec52de4dc667cba0b2fc4db1e1ffc42cb.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T03:01:02.000000Z",
"updated_at": "2018-05-15T09:20:24.000000Z",
"language_name": "Thai",
"language_code": "TH"
}
],
"content_bottom": "",
"image": "",
"active": "1",
"created_at": "2011-07-28T02:54:09.000000Z",
"updated_at": "2011-08-08T03:51:52.000000Z"
},
{
"id": 87,
"name": "add the polite particle ‘³na’",
"show_name": "0",
"code": "ST1C2L033",
"lesson_id": "78",
"sort_order": "10",
"content_top": "For politeness, when you use the word ‘what?’ on its own you should always add the polite particle ‘³na’. Note: This is a different polite particle than the ‘°na’ used in conjunction with ‘k°rap’ / ‘§ka’. ",
"slide": [
{
"id": 321,
"sub_lesson_id": "86",
"code": "ST1C2L028",
"isaana": "³A-ry",
"thai": "อะไร",
"english": "What? ",
"english_word_order": "",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/34322cde0baa04df7ed58295863e390c7a489a98.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/ff791dbc630a4407eec2d4bdb4cbf677fac820bb.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/ed99dca146d83b40c8a91b1a2cc58844fa9d8162.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/5ca41fb350d2713194b00071fab749d36d376f8c.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:55:06.000000Z",
"updated_at": "2011-07-28T02:55:21.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 322,
"sub_lesson_id": "86",
"code": "ST1C2L029",
"isaana": "(Kun) cªheu ³a-ry?",
"thai": "คุณชื่ออะไร",
"english": "What’s your name?",
"english_word_order": "(You name what?)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/fff77db9e63b1ed203ef186c1252dee9ee47f1e6.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/85315f3e7892fdefff80dbc17a140fed7a1a0812.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/158079fe8d6aab8d95201d2c945a378b971a5e04.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/d9f7c4170a13336b95846b995add06f3537e6730.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:56:23.000000Z",
"updated_at": "2011-08-19T00:20:38.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 323,
"sub_lesson_id": "86",
"code": "ST1C2L030",
"isaana": "Cªheu B°orb",
"thai": "ชื่อบ๊อบ",
"english": "My name is Bob ",
"english_word_order": "(Name Bob)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/783d893e197d718c9d32624cf6aa6eff25113dc2.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/fae572b408441871d16d9335675f88895c533f4e.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/7b80d533c30f9d7839a1cd5f058c10092960dcf8.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/57ce04c653580cdf525af9b49d8deb19f49c9786.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:58:00.000000Z",
"updated_at": "2011-07-28T02:58:17.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 324,
"sub_lesson_id": "86",
"code": "ST1C2L031",
"isaana": "An-n°ee r§iak w§ah ³a-ry?",
"thai": "อันนี้เรียกว่าอะไร",
"english": "What’s this called?",
"english_word_order": "(This called what?)",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/8244e536e5bcd1f0383b322f0df04a31926888f2.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/0c31968d79a921bf8b2810d8b05b9d01c4f6898f.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/394021ec2ff89c15a607ce3fd31ba0835115b84a.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/9034801d15fb058ea4a2bc0ba545e92cc3ec63a2.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T02:59:24.000000Z",
"updated_at": "2011-07-28T03:00:02.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 325,
"sub_lesson_id": "86",
"code": "ST1C2L032",
"isaana": " R§iak w§ah d§ton °my ",
"thai": " เรียกว่าต้นไม้ ",
"english": "It’s called a tree",
"english_word_order": "",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/2725e831aaf141324cc62dc61300b95dd544d487.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/b95be383542085e2c3ef1500c86c7c432c8155f9.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/e66433b0437f6b1b6d0f65b61c8b13b4e27fd57d.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/88b3abbec52de4dc667cba0b2fc4db1e1ffc42cb.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T03:01:02.000000Z",
"updated_at": "2018-05-15T09:20:24.000000Z",
"language_name": "Thai",
"language_code": "TH"
},
{
"id": 326,
"sub_lesson_id": "87",
"code": "ST1C2L033a",
"isaana": "³A-ry ³na?",
"thai": "อะไรน่ะ",
"english": "What? / pardon?",
"english_word_order": "What p.p.? ",
"language_id": "1",
"slide": "https://learnspeakthai.com/uploads/images/slide/c2e01e9bdc3455275a60fc58640fef574920931a.jpg",
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/1c9490fdc1ae25dacdecba8d5054b8bc2e116595.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/c96b08c9ee6afdd3db503abb83dbec673768284b.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/dbfede0423eb13e4fae61f0bfe3f45ef52602868.mp3",
"sort_order": null,
"pause": "0",
"active": "1",
"created_at": "2011-07-28T03:04:40.000000Z",
"updated_at": "2021-02-16T21:57:32.000000Z",
"language_name": "Thai",
"language_code": "TH"
}
],
"content_bottom": "",
"image": "",
"active": "1",
"created_at": "2011-07-28T03:03:11.000000Z",
"updated_at": "2021-02-16T21:55:34.000000Z"
}
],
"GameList": [
{
"id": 1189,
"name": "Question words #1: Matching",
"code": "ST1C2G001a",
"chapter_id": "12",
"lesson_id": "78",
"content_top": "",
"game_type": "matching",
"word_source": "selection_from_all",
"words_to_display": "10",
"sort_order": "5",
"active": "1",
"is_free": 0,
"is_subscription": 1,
"created_at": "2014-10-07T06:38:48.000000Z",
"updated_at": "2014-10-07T10:25:07.000000Z"
},
{
"id": 1190,
"name": "Question words #2: Flash card",
"code": "ST1C2G001b",
"chapter_id": "12",
"lesson_id": "78",
"content_top": "",
"game_type": "flashcard",
"word_source": "selection_from_all",
"words_to_display": "10",
"sort_order": "6",
"active": "1",
"is_free": 0,
"is_subscription": 1,
"created_at": "2014-10-07T06:57:22.000000Z",
"updated_at": "2014-10-07T10:25:38.000000Z"
}
],
"Slideshow": [
{
"id": 321,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/ff791dbc630a4407eec2d4bdb4cbf677fac820bb.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/34322cde0baa04df7ed58295863e390c7a489a98.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/ed99dca146d83b40c8a91b1a2cc58844fa9d8162.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/5ca41fb350d2713194b00071fab749d36d376f8c.mp3"
},
{
"id": 322,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/85315f3e7892fdefff80dbc17a140fed7a1a0812.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/fff77db9e63b1ed203ef186c1252dee9ee47f1e6.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/158079fe8d6aab8d95201d2c945a378b971a5e04.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/d9f7c4170a13336b95846b995add06f3537e6730.mp3"
},
{
"id": 323,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/fae572b408441871d16d9335675f88895c533f4e.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/783d893e197d718c9d32624cf6aa6eff25113dc2.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/7b80d533c30f9d7839a1cd5f058c10092960dcf8.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/57ce04c653580cdf525af9b49d8deb19f49c9786.mp3"
},
{
"id": 324,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/0c31968d79a921bf8b2810d8b05b9d01c4f6898f.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/8244e536e5bcd1f0383b322f0df04a31926888f2.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/394021ec2ff89c15a607ce3fd31ba0835115b84a.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/9034801d15fb058ea4a2bc0ba545e92cc3ec63a2.mp3"
},
{
"id": 325,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/b95be383542085e2c3ef1500c86c7c432c8155f9.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/2725e831aaf141324cc62dc61300b95dd544d487.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/e66433b0437f6b1b6d0f65b61c8b13b4e27fd57d.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/88b3abbec52de4dc667cba0b2fc4db1e1ffc42cb.mp3"
},
{
"id": 326,
"pre_slide": "https://learnspeakthai.com/uploads/images/slide/1c9490fdc1ae25dacdecba8d5054b8bc2e116595.jpg",
"slide": "https://learnspeakthai.com/uploads/images/slide/c2e01e9bdc3455275a60fc58640fef574920931a.jpg",
"audio_en": "https://learnspeakthai.com/uploads/audio/audio_en/c96b08c9ee6afdd3db503abb83dbec673768284b.mp3",
"audio_th": "https://learnspeakthai.com/uploads/audio/audio_th/dbfede0423eb13e4fae61f0bfe3f45ef52602868.mp3"
}
]
}
}
I have created model for json. I want to append value in Array of english key from json.
I am doing --
var english_Array = [[String]] ()
guard let subLesson = userResponse.result?.subLesson else {return}
for i in subLesson {
english_Array.append(i.slide?[0].english ?? "" )
}
print(english_Array)
value:
[["What?"], ["What?]]
I need -
[["What?","What’s your name?","My name is Bob","What’s this called?","It’s called a tree"],
["What?","What’s your name?","My name is Bob","What’s this called?","It’s called a tree","What? / pardon?"]]
First of all there are two values for the same key "slide". You should fix it. for now lets consider they are in an array [slide1, slide2] for the key "slides".
var english_Array = [[String]] ()
for slide in subLesson.slides {
let english = slide.map { $0.english ?? "" }
english_Array.append(english_Array)
}
this should do it.
I am using QuickBooks Online API.
Documentation for the Account Object is here: https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/account
Sample Request URL:
GET /v3/company/<clientID>/query?query=<selectStatement>&minorversion=59
Content type:text/plain
Production Base URL:https://quickbooks.api.intuit.com
Sandbox Base URL:https://sandbox-quickbooks.api.intuit.com
Sample Query:
select * from Account where Metadata.CreateTime > '2014-12-31'
Sample Return:
{
"QueryResponse": {
"startPosition": 1,
"Account": [
{
"FullyQualifiedName": "Canadian Accounts Receivable",
"domain": "QBO",
"Name": "Canadian Accounts Receivable",
"Classification": "Asset",
"AccountSubType": "AccountsReceivable",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"CurrentBalanceWithSubAccounts": 0,
"sparse": false,
"MetaData": {
"CreateTime": "2015-06-23T09:38:18-07:00",
"LastUpdatedTime": "2015-06-23T09:38:18-07:00"
},
"AccountType": "Accounts Receivable",
"CurrentBalance": 0,
"Active": true,
"SyncToken": "0",
"Id": "92",
"SubAccount": false
},
{
"FullyQualifiedName": "MyClients",
"domain": "QBO",
"Name": "MyClients",
"Classification": "Asset",
"AccountSubType": "AccountsReceivable",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"CurrentBalanceWithSubAccounts": 0,
"sparse": false,
"MetaData": {
"CreateTime": "2015-07-13T12:34:47-07:00",
"LastUpdatedTime": "2015-07-13T12:34:47-07:00"
},
"AccountType": "Accounts Receivable",
"CurrentBalance": 0,
"Active": true,
"SyncToken": "0",
"Id": "93",
"SubAccount": false
},
{
"FullyQualifiedName": "MyJobs",
"domain": "QBO",
"Name": "MyJobs",
"Classification": "Asset",
"AccountSubType": "AccountsReceivable",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"CurrentBalanceWithSubAccounts": 0,
"sparse": false,
"MetaData": {
"CreateTime": "2015-01-13T10:29:27-08:00",
"LastUpdatedTime": "2015-01-13T10:29:27-08:00"
},
"AccountType": "Accounts Receivable",
"CurrentBalance": 0,
"Active": true,
"SyncToken": "0",
"Id": "91",
"SubAccount": false
}
],
"maxResults": 3
},
"time": "2015-07-13T12:35:57.651-07:00"
}
In the Sample Request URL, I need to determine what to type into the "selectStatement".
I have found additional documentation here:
https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/data-queries
You have an example of what to put for selectStatement in your post:
select * from Account where Metadata.CreateTime > '2014-12-31'
e.g.:
/v3/company/<clientID>/query?query=select * from Account where Metadata.CreateTime > '2014-12-31'&minorversion=59
{
"status": true,
"error": false,
"data": [
{
"type": 0,
"title": "",
"description": "",
"data": [
{
"images": "/media/banner/Glocart%20Shop/Glocart-Shop_moVB3tP.jpg",
"is_external": true,
"link": "https://www.wikipedia.org/",
"product_id": null,
"offer_list_id": null,
"product_list_id": null
},
{
"images": "/media/banner/Grocery/Grocery_m341Az6.jpg",
"is_external": false,
"link": null,
"product_id": null,
"offer_list_id": 1,
"product_list_id": null
}
]
},
{
"type": 1,
"title": "Categories",
"description": "",
"data": [
{
"category_name": "Beverages",
"category_id": 5,
"category_icon": "/media/category_icon_upload_location/61ho157I07L._SX522__WpWCZ7h.jpg"
},
{
"category_name": "Tea & Coffee",
"category_id": 6,
"category_icon": "/media/category_icon_upload_location/Lipton-Green-Tea-Bags-250-SDL859816919-1-31762.jpg"
},
{
"category_name": "Body Care",
"category_id": 3,
"category_icon": "/media/category_icon_upload_location/nourishing-body-lotion-100ml_1024x1024.png"
},
{
"category_name": "Personal Hygiene",
"category_id": 7,
"category_icon": "/media/category_icon_upload_location/lif0259_2_1.jpg"
},
{
"category_name": "Jams & Preserves",
"category_id": 32,
"category_icon": "/media/category_icon_upload_location/kissan-mixed-fruit-jam-500-gm-164390973-ymzpr.jpg"
},
{
"category_name": "Air Fresheners",
"category_id": 28,
"category_icon": "/media/category_icon_upload_location/Godrej_Aer_Home_Air_Freshener_Spray_Morning_Misty_Meadows__fkCoOzL.jpg"
},
{
"category_name": "Chocolate",
"category_id": 35,
"category_icon": "/media/category_icon_upload_location/71p5hUVC0eL._SX569_.jpg"
},
{
"category_name": "Cosmetics & Makeup",
"category_id": 27,
"category_icon": "/media/category_icon_upload_location/81oA3GcTyRL._SL1500_.jpg"
},
{
"category_name": "Personal care",
"category_id": 26,
"category_icon": "/media/category_icon_upload_location/gillette-guard-3-card-blade-pack_rixer.png"
}
]
},
{
"type": 2,
"title": "Fresh Deals",
"description": "Today's Arrival",
"data": [
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
}
]
},
{
"type": 3,
"title": "",
"description": "",
"data": [
{
"images": "/media/banner/Glocart%20Shop/Glocart-Shop_moVB3tP.jpg",
"is_external": true,
"link": "https://www.wikipedia.org/",
"product_id": null,
"offer_list_id": null,
"product_list_id": null
},
{
"images": "/media/banner/Glocart%20Shop/Glocart-Shop_moVB3tP.jpg",
"is_external": true,
"link": "https://www.wikipedia.org/",
"product_id": null,
"offer_list_id": null,
"product_list_id": null
}
]
},
{
"type": 4,
"title": "",
"description": "",
"data": [
{
"images": "/media/banner/Glocart%20Shop/Glocart-Shop_moVB3tP.jpg",
"is_external": true,
"link": null,
"product_id": null,
"offer_list_id": null,
"product_list_id": null
}
]
},
{
"type": 5,
"title": "Discount Range",
"description": "",
"data": [
{
"banner": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"discount_from": 50,
"discount_to": 60
},
{
"banner": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"discount_from": 40,
"discount_to": 100
}
]
},
{
"type": 2,
"title": "Top Deals",
"description": "Upto 45% discount",
"data": [
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
}
]
},
{
"type": 0,
"title": "",
"description": "",
"data": {
"images": "/media/banner/Glocart%20Shop/Glocart-Shop_moVB3tP.jpg",
"is_external": true,
"link": "https://www.wikipedia.org/",
"product_id": null,
"offer_list_id": null,
"product_list_id": null
}
},
{
"type": 6,
"title": "Suggested for you",
"description": "",
"data": [
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
},
{
"product_id": 193,
"image_url": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"product_name": "UNILEVER KSN PINEAPPLE SQH 750ML-RS.15 PRICE OFF",
"offer_price": 14500,
"normal_price": 15500,
"is_in_cart": false,
"cart_qty": 0
}
]
},
{
"type": 0,
"title": "",
"description": "",
"data": {
"images": "/media/banner/Grocery/Grocery_m341Az6.jpg",
"is_external": false,
"link": null,
"product_id": null,
"offer_list_id": 1,
"product_list_id": null
}
},
{
"type": 7,
"title": "",
"description": "",
"data": [
{
"banner": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"category_name": "Personal Care",
"category_id": 1,
"have_sub_category": true,
"sub_categories": [
{
"category_name": "Chocolate",
"category_id": 35,
"category_icon": "/media/category_icon_upload_location/71p5hUVC0eL._SX569_.jpg"
},
{
"category_name": "Chocolate",
"category_id": 35,
"category_icon": "/media/category_icon_upload_location/71p5hUVC0eL._SX569_.jpg"
}
]
}
]
},
{
"type": 7,
"title": "",
"description": "",
"data": [
{
"banner": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"category_name": "Beauty Care",
"category_id": 2,
"have_sub_category": false,
"sub_categories": []
}
]
},
{
"type": 7,
"title": "",
"description": "",
"data": [
{
"banner": "/media/product_images/61XJQZV8YxL._SX425_.jpg",
"category_name": "Home Care",
"category_id": 3,
"have_sub_category": false,
"sub_categories": []
}
]
}
],
"cart_items_count": 5,
"total_cart_price": 30000,
"is_authenticated": true,
"new_notification_count": 1,
"cash_back_msg": "Dummy Cash Back message"
}
I have created one..but shows error
struct Home2Response: Codable {
var status, error: Bool?
var data: [Home2ResponseDatum]?
var cartItemsCount, totalCartPrice: Int?
var isAuthenticated: Bool?
var newNotificationCount: Int?
var cashBackMsg: String?
enum CodingKeys: String, CodingKey {
case status, error, data
case cartItemsCount = "cart_items_count"
case totalCartPrice = "total_cart_price"
case isAuthenticated = "is_authenticated"
case newNotificationCount = "new_notification_count"
case cashBackMsg = "cash_back_msg"
}
}
// MARK: - Home2ResponseDatum
struct Home2ResponseDatum: Codable {
var type: Int?
var title: String?
var datumDescription: String?
var data: [Any]?
enum CodingKeys: String, CodingKey {
case type, title
case datumDescription = "description"
case data
}
}
The name in JSON should match the one in your struct.
Change datumDescription into description.
struct Data : Codable {
let type : Int?
let title : String?
let description : String?
let data : [Data]?
For API v2 there was a table which related language_id (integer) to language description which I built into my app so that I could match my user language to that of the survey.
Is there a similar table for v3 to relate language (string) to the language description; I couldn't find one.
It would be good to know what language codes are currently possible.
In V2 survey showed language_id which was an internal number that references a language, the table is located here.
In V3 the language used is the standard ISO language codes used everywhere (instead of a number it'll be en, es, fr for example. Here's a table of language codes I just searched up. Maybe a similar table should be added to the API v3 docs.
survey_languages = [
{"name": "English", "id": 1, "code": "en"},
{"name": "Albanian", "id": 24, "code": "sq"},
{"name": "Arabic", "id": 25, "code": "ar"},
{"name": "Armenian", "id": 26, "code": "hy"},
{"name": "Basque", "id": 27, "code": "eu"},
{"name": "Bengali", "id": 28, "code": "bn"},
{"name": "Bosnian", "id": 29, "code": "bs"},
{"name": "Bulgarian", "id": 30, "code": "bg"},
{"name": "Catalan", "id": 31, "code": "ca"},
{"name": "Chinese (Simplified)", "id": 2, "code": "zh-cn"},
{"name": "Chinese (Traditional)", "id": 3, "code": "zh-tw"},
{"name": "Portuguese (Brazilian)", "id": 17, "code": "pt-br"},
{"name": "Portuguese (Iberian)", "id": 16, "code": "pt"},
{"name": "Croatian", "id": 32, "code": "hr"},
{"name": "Czech", "id": 33, "code": "cs"},
{"name": "Danish", "id": 4, "code": "da"},
{"name": "Dutch", "id": 5, "code": "nl"},
{"name": "Estonian", "id": 34, "code": "et"},
{"name": "Filipino", "id": 35, "code": "tl"},
{"name": "Finnish", "id": 6, "code": "fi"},
{"name": "French", "id": 7, "code": "fr"},
{"name": "Georgian", "id": 36, "code": "ka"},
{"name": "German", "id": 8, "code": "de"},
{"name": "Greek", "id": 9, "code": "el"},
{"name": "Hebrew", "id": 37, "code": "he"},
{"name": "Hindi", "id": 38, "code": "hi"},
{"name": "Hungarian", "id": 39, "code": "hu"},
{"name": "Icelandic", "id": 40, "code": "is"},
{"name": "Indonesian", "id": 41, "code": "id"},
{"name": "Irish", "id": 42, "code": "ga"},
{"name": "Italian", "id": 10, "code": "it"},
{"name": "Japanese", "id": 11, "code": "ja"},
{"name": "Korean", "id": 12, "code": "ko"},
{"name": "Kurdish", "id": 43, "code": "ku"},
{"name": "Latvian", "id": 44, "code": "lv"},
{"name": "Lithuanian", "id": 45, "code": "lt"},
{"name": "Macedonian", "id": 46, "code": "mk"},
{"name": "Malay", "id": 13, "code": "ms"},
{"name": "Malayalam", "id": 47, "code": "ml"},
{"name": "Norwegian", "id": 14, "code": "no"},
{"name": "Persian", "id": 48, "code": "fa"},
{"name": "Polish", "id": 15, "code": "pl"},
{"name": "Punjabi", "id": 49, "code": "pa"},
{"name": "Romanian", "id": 50, "code": "ro"},
{"name": "Russian", "id": 18, "code": "ru"},
{"name": "Serbian", "id": 51, "code": "sr"},
{"name": "Slovak", "id": 52, "code": "sk"},
{"name": "Slovenian", "id": 53, "code": "sl"},
{"name": "Spanish", "id": 19, "code": "es"},
{"name": "Swahili", "id": 54, "code": "sw"},
{"name": "Swedish", "id": 20, "code": "sv"},
{"name": "Tamil", "id": 55, "code": "ta"},
{"name": "Telugu", "id": 56, "code": "te"},
{"name": "Thai", "id": 57, "code": "th"},
{"name": "Turkish", "id": 21, "code": "tr"},
{"name": "Ukrainian", "id": 22, "code": "uk"},
{"name": "Vietnamese", "id": 58, "code": "vi"},
{"name": "Welsh", "id": 59, "code": "cy"},
]
I want to create invoice in my Quickbooks account through API from my rails application, but it requires to add customer and item before creating invoice. But I can't get the idea how to add customer and items through API. Can you suggest me???
Thanks.
Start here:
https://developer.intuit.com/
Follow the docs (https://developer.intuit.com/docs/0100_accounting) and implement OAuth to connect to QuickBooks Online.
Create customers by HTTP POSTing a JSON request to QuickBooks Online:
https://developer.intuit.com/docs/api/accounting/Customer
The JSON request will look something like this:
{
"BillAddr": {
"Line1": "123 Main Street",
"City": "Mountain View",
"Country": "USA",
"CountrySubDivisionCode": "CA",
"PostalCode": "94042"
},
"Notes": "Here are other details.",
"Title": "Mr",
"GivenName": "James",
"MiddleName": "B",
"FamilyName": "King",
"Suffix": "Jr",
"FullyQualifiedName": "King Groceries",
"CompanyName": "King Groceries",
"DisplayName": "King's Groceries",
"PrimaryPhone": {
"FreeFormNumber": "(555) 555-5555"
},
"PrimaryEmailAddr": {
"Address": "jdrew#myemail.com"
}
}
You'll get back something like this:
{
"Customer": {
"Taxable": true,
"BillAddr": {
"Id": "112",
"Line1": "123 Main Street",
"City": "Mountain View",
"Country": "USA",
"CountrySubDivisionCode": "CA",
"PostalCode": "94042"
},
"Notes": "Here are other details.",
"Job": false,
"BillWithParent": false,
"Balance": 0,
"BalanceWithJobs": 0,
"CurrencyRef": {
"value": "USD",
"name": "United States Dollar"
},
"PreferredDeliveryMethod": "Print",
"domain": "QBO",
"sparse": false,
"Id": "67",
"SyncToken": "0",
"MetaData": {
"CreateTime": "2015-07-23T10:58:12-07:00",
"LastUpdatedTime": "2015-07-23T10:58:12-07:00"
},
"Title": "Mr",
"GivenName": "James",
"MiddleName": "B",
"FamilyName": "King",
"Suffix": "Jr",
"FullyQualifiedName": "King's Groceries",
"CompanyName": "King Groceries",
"DisplayName": "King's Groceries",
"PrintOnCheckName": "King Groceries",
"Active": true,
"PrimaryPhone": {
"FreeFormNumber": "(555) 555-5555"
},
"PrimaryEmailAddr": {
"Address": "jdrew#myemail.com"
},
"DefaultTaxCodeRef": {
"value": "2"
}
},
"time": "2015-07-23T10:58:12.099-07:00"
}
Make sure you save that Id attribute, you'll need that later.
The process for creating Items is similar. Docs:
https://developer.intuit.com/docs/api/accounting/Item
Everything is just standard OAuth requests. Go grab an OAuth library for Rails and you should be all set.