-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathTaskManager.swift
39 lines (33 loc) · 952 Bytes
/
TaskManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// TaskManager.swift
// TaskApplication
//
// Created by Michael Crump
// Copyright (c) 2015 Michael Crump. All rights reserved.
// Changes by David Phillip Oster on 2/17/19.
// Added isDone BOOL here and in data model
// Rewrote Data Model to use just Core Data, without the unnecessary Dictionary<String, String>
import UIKit
var taskMgr: TaskManager = TaskManager()
class TaskManager: NSObject {
var tasks: [Task]
var taskPersistence: TaskPersistence
override init() {
taskPersistence = TaskPersistence()
tasks = taskPersistence.list()
}
func addTask(name:String, desc: String, isDone: Bool) {
if let task = taskPersistence.construct() {
task.desc = desc
task.name = name
task.isDone = isDone as NSNumber
tasks.append(task)
}
}
func removeTask(index: Int) {
let task = tasks[index]
if taskPersistence.remove(instance: task) {
tasks.remove(at: index)
}
}
}