This is a simple class swift. You may take this as an example. I hope we can be of your help.
class UserBean:NSObject,NSCoding {
var idUser:NSNumber?
var username:String?
var password:String?
var email:String?
var token:String?
var fonte:String?
var idFacebook:String?
var uuid:String?
var profilo = UserProfileBean()
override init() {
super.init()
self.profilo = UserProfileBean()
}
required init?(coder aDecoder: NSCoder) {
idUser = aDecoder.decodeObjectForKey("idUser") as? NSNumber
username = aDecoder.decodeObjectForKey("username") as? String
password = aDecoder.decodeObjectForKey("password") as? String
email = aDecoder.decodeObjectForKey("email") as? String
token = aDecoder.decodeObjectForKey("token") as? String
fonte = aDecoder.decodeObjectForKey("fonte") as? String
idFacebook = aDecoder.decodeObjectForKey("idFacebook") as? String
uuid = (aDecoder.decodeObjectForKey("uuid") as? String)!
profilo = (aDecoder.decodeObjectForKey("profilo") as? UserProfileBean)!
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(idUser, forKey: "idUser")
aCoder.encodeObject(username, forKey: "username")
aCoder.encodeObject(password, forKey: "password")
aCoder.encodeObject(email, forKey: "email")
aCoder.encodeObject(token, forKey: "token")
aCoder.encodeObject(fonte, forKey: "fonte")
aCoder.encodeObject(idFacebook ,forKey: "idFacebook")
aCoder.encodeObject(uuid ,forKey: "idFacebook")
aCoder.encodeObject(profilo,forKey: "profilo")
}
}