Error: using raw type "NSObject" in Xcode

I am creating a new data structure called "CheckItem" (I am doing a Todo project)

and I let the CheckItem class inherit NSObject and NSCoding

But Xcode warns of a compile-time error on line 1:

 class CheckItem : NSObject,NSCoding { 

Hint: Using the undeclared type "NSObject" (and "NSCoding")

The whole class is as follows:

  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 out my mistake? Thank you very much!

+6
source share
1 answer

Put the following statement in your class:

 import Foundation 

Even after that, you will need to implement the following methods for compilation. This is because you implement the NSCoding protocol NSCoding that your class matches it by doing the following:

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

All Articles