Instance member cannot be used on type

后端 未结 8 1908
遥遥无期
遥遥无期 2020-11-29 04:13

I have the following class:

class ReportView: NSView {  
    var categoriesPerPage = [[Int]]()
    var numPages: Int = { return categoriesPerPage.count }
}
<         


        
8条回答
  •  半阙折子戏
    2020-11-29 04:53

    For anyone else who stumbles on this make sure you're not attempting to modify the class rather than the instance! (unless you've declared the variable as static)

    eg.

    MyClass.variable = 'Foo' // WRONG! - Instance member 'variable' cannot be used on type 'MyClass'
    
    instanceOfMyClass.variable = 'Foo' // Right!
    

提交回复
热议问题