我怎么做错了?

 class ActivityDetailsModel {
    var ActivityProfile: [[String]]
    init(ActivityProfile: [[String]]){
        self.ActivityProfile = ActivityProfile
    }
}

var act = ActivityDetailsModel(ActivityProfile: ["cell2"+"firName": "two"])


给出类型参数为(ActivityProfile:[String:String])的'ActivityDetailsModel'类型的不能调用初始化程序

最佳答案

变量ActivityProfile的类型签名是ArrayArray而不是预期的Array Dictionary

这使用替代语法使其清晰

class ActivityDetailsModel : Printable {
  var activityProfile : [[String:String]]

  init(activityProfile: [[String:String]]) {
    self.activityProfile = activityProfile
  }

  var description : String {
    return activityProfile.description
  }
}

var act = ActivityDetailsModel(activityProfile: [["cell2"+"firName": "two"]])
println(act)


PS:更容易阅读以小写字母开头的变量名

09-19 12:40