Skip to content

Instantly share code, notes, and snippets.

@jungchris
Created April 15, 2016 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jungchris/900f3d49929c997381a19cdc7eb2a862 to your computer and use it in GitHub Desktop.
Save jungchris/900f3d49929c997381a19cdc7eb2a862 to your computer and use it in GitHub Desktop.
Swift ItemModel
//
// 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")
}
}
@jungchris
Copy link
Author

Code from tutorial to be used in Fire project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment