Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created December 3, 2017 12:35
Show Gist options
  • Save azamsharp/45d8d035e1f2be0a4ee9eeed00f8fd21 to your computer and use it in GitHub Desktop.
Save azamsharp/45d8d035e1f2be0a4ee9eeed00f8fd21 to your computer and use it in GitHub Desktop.
User NSCoding
public class User : NSObject, NSCoding {
var username :String!
var password :String!
var userId :String!
init(username :String, password :String) {
self.username = username
self.password = password
}
public func encode(with aCoder: NSCoder) {
aCoder.encode(self.userId,forKey: "userId")
aCoder.encode(self.username, forKey: "username")
aCoder.encode(self.password, forKey: "password")
}
public required init?(coder aDecoder: NSCoder) {
self.userId = aDecoder.decodeObject(forKey: "userId") as! String
self.username = aDecoder.decodeObject(forKey: "username") as! String
self.password = aDecoder.decodeObject(forKey: "password") as! String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment