Instance member cannot be used on type of custom class

前端 未结 3 1342
耶瑟儿~
耶瑟儿~ 2020-11-28 00:06

I have a classe named \"whisky builder\" which only initiates the new Whisky. Now i would like to add the new added whiskies in my \"WhiskyOverViewController\". But I face t

相关标签:
3条回答
  • 2020-11-28 00:35

    The two types must be incompatible with each other. Just like you cannot assign a UIImage to a String, your program won't let you assign a [WhiskyBuilder] array type to a WhiskyOverViewController type. You must have declared stringArray globally, because otherwise Swift would infer its type.

    0 讨论(0)
  • 2020-11-28 00:41

    What you need there is a read only computed property:

    var stringArray: [String] { 
        return whiskyArray.map{$0.whiskyName!} 
    }
    
    0 讨论(0)
  • 2020-11-28 00:41

    You need to move this code to a function:

    let stringArray = whiskyArray.map({$0.whiskyName!})
    
    0 讨论(0)
提交回复
热议问题