Instance member cannot be used on type

2019-01-08 21:21发布

I have the following class:

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

Compilation fails with the message:

Instance member 'categoriesPerPage' cannot be used on type 'ReportView'

What does this mean?

7条回答
Evening l夕情丶
2楼-- · 2019-01-08 22:05

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 attribute.

You can make your class method an instance method by removing class attribute.

查看更多
登录 后发表回答