4thSpace
4thSpace

Reputation: 44352

Why is type undeclared?

I have a very simple example that I can't get to work. Both classes are in the same iOS project. I get this error when I build:

Use of undeclared type 'classB'

It happens in classA on the static var line.

import UIKit

class classB: NSObject {
    var temp:Int?
}

import UIKit

class classA: NSObject {
    static var classBList:[classB]?
}

Any idea what I'm doing wrong?

Upvotes: 0

Views: 45

Answers (1)

Pradeep K
Pradeep K

Reputation: 3661

The reason why you might get this error is if the ClassB file is not included in the project. If classA and classB are in separate files then verify that classB is included in the project. The reason why you are getting this error is because the compiler is not finding the class definition of classB. This can happen if the file is not included in the target.

Upvotes: 1

Related Questions