Cannot convert value of type '() -> _' to specified type 'Town.Size'

前端 未结 2 672
栀梦
栀梦 2021-01-04 17:00

Am getting this issue with this struct, on the line which reads \"lazy var townSize: Size ={\" and can\'t figure out what the issue is.

struct Town {

             


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 17:51

    You incorrectly declared lazy var it should be declared like this

     lazy var townSize: Size = {
            switch self.population {
            case 0...10000:
                return Size.Small
            case 10001...100000:
                return Size.Medium
            default:
                return Size.Large
            }
        }()
    

提交回复
热议问题