I'm trying to create some sort of initWithDictionary initializer for one of my model in Swift. This is what I'm trying to do:
class CityModel: NSObject {
var country: String
var mapLat: String
var mapLng: String
var mapZoom: Int
var name: String
var nameShort: String
var timezone: String
var token: String
init(country: String, mapLat: String, mapLng: String, mapZoom: Int, name: String, nameShort: String, timezone: String, token: String) {
self.country = country
self.mapLat = mapLat
self.mapLng = mapLng
self.mapZoom = mapZoom
self.name = name
self.nameShort = nameShort
self.timezone = timezone
self.token = token
}
convenience init(dict: Dictionary<String, AnyObject>) {
self.init(
country: (dict["country"] as String),
mapLat: (dict["mapLat"] as String), // error
mapLng: (dict["mapLng"] as String),
mapZoom: (dict["mapZoom"] as Int),
name: (dict["name"] as String),
nameShort: (dict["nameShort"] as String),
timezone: (dict["timezone"] as String),
token: (dict["token"] as String)
)
}
}
I'm getting the following error:
CityModel.swift:34:18: Extra argument 'mapLat' in call
And I'm afraid I have no idea what I'm doing wrong. Any idea?