我是swift的新手,我跟着树屋课,
let currentWeather = Current(weatherDictionary: weatherDictionary)
并且不知道为什么我应该使用Current(weatherDictionary: weatherDictionary)
来传递编译
但不是Current(weatherDictionary: NSDictionary)
因为我认为我将weatherDictionary声明为NSDictionary类型
let weatherDictionary: NSDictionary =
NSJSONSerialization.JSONObjectWithData(dataObject, options: nil, error: nil) as NSDictionary
let currentWeather = Current(weatherDictionary: weatherDictionary)
struct Current {
var currentTime: String?
var temperature: Int
var humidity: Double
var summary: String
var icon: String
init(weatherDictionary: NSDictionary){
答案 0 :(得分:0)
weatherDictionary
是您的实例的名称,这就是您需要使用它的原因。
您将参数声明为NSDictionary,但就是这样。使用命名参数(name:instance)时使用它;第一个参数是名称,第二个参数是需要NSDictonary类型的对象实例。