SDK 8.3不可变的值...只有名为'追加'的变异成员。

时间:2015-04-13 10:43:28

标签: ios

我更新到Xcode SDK 8.3和Swift 1.2:我使用新的菜单项自动转换:编辑 - >转换 - > “到最新的Swift语法”。它解决了所有的问题?错误,但我留下了这个:

  

类型'[DetailView]'的不可变值只有名为'append'的变异成员

类DetailView

class DetailView {
    var title: String
    var icon: UIImage
    var fontColor: UIColor
    var highlightOpaqueColor: UIColor

    init(title: String, icon:UIImage, fontColor: UIColor, highlightOpaqueColor: UIColor){
        self.title = title
        self.icon = icon
        self.fontColor = fontColor
        self.highlightOpaqueColor = highlightOpaqueColor


}

类DetailViewSteps:DetailView

class DetailViewSteps:DetailView {

    override init(
        title: String,
        icon: UIImage,
        fontColor: UIColor,
        highlightOpaqueColor:UIColor){

            super.init(
                title: title,
                icon: icon,
                fontColor:fontColor,
                highlightOpaqueColor:highlightOpaqueColor,

    }

类DetailViewInstanceList

class DetailViewInstanceList {


    let detailView:[DetailView] = []

class var sharedInstance: DetailViewInstanceList {
    struct Singleton {
        static let instance = DetailViewInstanceList()
    }
    return Singleton.instance
}


    let assets = Assets()

    init(){
        println("setting up DetailViewInstanceList")


    var steps = DetailViewSteps(
        title: "Steps",
        icon: UIImage(named: assets.stepsIconFileName)!,
        fontColor: assets.stepsFontColor,
        highlightOpaqueColor: assets.stepsOpaqueColor,


    //Add it to the array
        detailView.append(steps) <-- error!

错误发生在最后一行。我想用var steps = DetailViewSteps初始化类(...会解决不可变的问题,但是没有。任何帮助都会非常感激!谢谢

1 个答案:

答案 0 :(得分:1)

var detailView:[DetailView] = []

let是不可变的,var是可变的。