Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import ObjectMapper
- public class User: NSObject, Mappable, NSCoding {
- public var id: Int!
- public var name: String!
- public required init?(map: Map) {
- }
- public func mapping(map: Map) {
- id <- map["id"]
- name <- map["name"]
- }
- required public init(coder: NSCoder) {
- id = coder.decodeObject(forKey: "id") as! Int
- name = coder.decodeObject(forKey: "name") as! String
- }
- public func encode(with aCoder: NSCoder) {
- aCoder.encode(id, forKey: "id")
- aCoder.encode(name, forKey: "name")
- }
- }
- let user = User()
- user.id = 0
- user.name = "name"
- let data = NSKeyedArchiver.archivedData(withRootObject: user)
- let unarchivedUser = NSKeyedUnarchiver.unarchiveObject(with: data) as! User
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement