Created
April 26, 2016 21:24
-
-
Save corybohon/01ab326fb6edf91d48ddd2940abce372 to your computer and use it in GitHub Desktop.
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
// | |
// TodoItem.swift | |
// Reminderz | |
// | |
// Created by Cory Bohon on 4/21/16. | |
// Copyright © 2016 MartianCraft. All rights reserved. | |
// | |
import Foundation | |
class TodoItem: NSObject, NSCoding { | |
var todoName: String = "" | |
var todoDueDate: NSDate = NSDate() | |
required init?(coder aDecoder: NSCoder) { | |
self.todoName = aDecoder.decodeObjectForKey("todoName") as! String | |
self.todoDueDate = aDecoder.decodeObjectForKey("todoDueDate") as! NSDate | |
} | |
override init() { | |
} | |
func encodeWithCoder(aCoder: NSCoder) { | |
aCoder.encodeObject(self.todoName, forKey: "todoName") | |
aCoder.encodeObject(self.todoDueDate, forKey: "todoDueDate") | |
} | |
// Convinience setter method | |
func setTodo(name: String, dueDate: NSDate) { | |
self.todoName = name | |
self.todoDueDate = dueDate | |
} | |
override func isEqual(object: AnyObject?) -> Bool { | |
if let secondTodo: TodoItem = object as? TodoItem { | |
var objectsAreSame: Bool = false | |
if (secondTodo.todoName == self.todoName) && | |
(secondTodo.todoDueDate.isEqualToDate(self.todoDueDate)) { | |
objectsAreSame = true | |
} | |
return objectsAreSame | |
} | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment