Created
April 15, 2016 14:31
-
-
Save jungchris/900f3d49929c997381a19cdc7eb2a862 to your computer and use it in GitHub Desktop.
Swift ItemModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ItemModel.swift | |
// HelloToDoSwift | |
// | |
// Created by Chris Jungmann on 4/2/16. | |
// Copyright © 2016 Chris Jungmann. All rights reserved. | |
// | |
// http://nshipster.com/nscoding/ | |
import UIKit | |
class ItemModel: NSObject, NSCoding { | |
var itemName: String | |
var itemDesciption: String | |
// Memberwise initializer | |
init(itemName: String, itemDescription: String) { | |
self.itemName = itemName | |
self.itemDesciption = itemDescription | |
} | |
// MARK: NSCoding | |
required convenience init?(coder decoder: NSCoder) { | |
guard let itemName = decoder.decodeObjectForKey("itemName") as? String, | |
let itemDesciption = decoder.decodeObjectForKey("itemDesciption") as? String | |
else { return nil } | |
self.init( | |
itemName: itemName, | |
itemDescription: itemDesciption | |
) | |
} | |
func encodeWithCoder(coder: NSCoder) { | |
coder.encodeObject(self.itemName, forKey: "itemName") | |
coder.encodeObject(self.itemDesciption, forKey: "itemDesciption") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code from tutorial to be used in Fire project