2
我正嘗試在Swift中爲我的某個模型創建某種initWithDictionary
初始值設定項。這就是我想要做的事:Swift中的便捷初始值設定程序
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)
)
}
}
,我發現了以下錯誤:
CityModel.swift:34:18: Extra argument 'mapLat' in call
我怕我不知道我做錯了。任何想法?
它解決了這個問題。謝謝。 – 2014-10-02 08:23:37