Microos
Microos

Reputation: 1768

Error :Use of undeclared type 'NSObject' in Xcode

I build a new Data structure called "CheckItem"(I am doing a Todo project)

and I let CheckItem class inherit the NSObject and NSCoding

But Xcode alert the compile-time error at line 1:

class CheckItem : NSObject,NSCoding {

the hint is : Use of undeclared type 'NSObject'(and 'NSCoding')

The whole class as follow:

 class CheckItem : NSObject,NSCoding {
        var text: String
        var isDone :Bool
        var imageName :String
        init(text: String,isDone: Bool,imageName: String){
            self.text = text
            self.isDone = isDone
            self.imageName = imageName
        }
        init(text: String,isDone: Bool){
            self.text = text
            self.isDone = isDone
            self.imageName = "No Icon"
        }

}

Can you point my error? Thank you very much!

Upvotes: 8

Views: 4269

Answers (1)

Abhinav
Abhinav

Reputation: 38162

Put following statement top in your class:

import Foundation

Even after that you would need to implement following methods to be able to compile. This is because you are implementing NSCoding protocol so your class must conform to it by implementing these:

public func encodeWithCoder(aCoder: NSCoder)
public init?(coder aDecoder: NSCoder)

Upvotes: 14

Related Questions