Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error :Use of undeclared type 'NSObject' in Xcode

Tags:

xcode

ios

swift

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!

like image 500
Microos Avatar asked Oct 05 '15 12:10

Microos


1 Answers

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)
like image 69
Abhinav Avatar answered Nov 08 '22 16:11

Abhinav