Instance member cannot be used on type

后端 未结 8 1881
遥遥无期
遥遥无期 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 05:06

    It is saying you have an instance variable (the var is only visible/accessible when you have an instance of that class) and you are trying to use it in the context of a static scope (class method).

    You can make your instance variable a class variable by adding static/class attribute.

    You instantiate an instance of your class and call the instance method on that variable.

提交回复
热议问题