Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
B73804E7221DCC8E00CD9E59 /* TaskController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B73804E6221DCC8D00CD9E59 /* TaskController.swift */; };
B73804E9221F729500CD9E59 /* SwitchTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B73804E8221F729500CD9E59 /* SwitchTableViewCell.swift */; };
B761071E22136DDD001F79B6 /* Task + Convenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = B761071D22136DDD001F79B6 /* Task + Convenience.swift */; };
B7BA6EE221F7A442004A3C70 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7BA6EE121F7A442004A3C70 /* AppDelegate.swift */; };
B7BA6EE721F7A442004A3C70 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B7BA6EE521F7A442004A3C70 /* Main.storyboard */; };
Expand All @@ -19,6 +21,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
B73804E6221DCC8D00CD9E59 /* TaskController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskController.swift; sourceTree = "<group>"; };
B73804E8221F729500CD9E59 /* SwitchTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchTableViewCell.swift; sourceTree = "<group>"; };
B761071D22136DDD001F79B6 /* Task + Convenience.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Task + Convenience.swift"; sourceTree = "<group>"; };
B7BA6EDE21F7A442004A3C70 /* Task.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Task.app; sourceTree = BUILT_PRODUCTS_DIR; };
B7BA6EE121F7A442004A3C70 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -43,6 +47,61 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
B73804EA22248AB600CD9E59 /* Model */ = {
isa = PBXGroup;
children = (
B761071D22136DDD001F79B6 /* Task + Convenience.swift */,
B7BA6EE821F7A442004A3C70 /* Task.xcdatamodeld */,
B7BA6EFA21F7D585004A3C70 /* CoreDataStack.swift */,
);
path = Model;
sourceTree = "<group>";
};
B73804EB22248AC200CD9E59 /* Controllers */ = {
isa = PBXGroup;
children = (
B73804EC22248AC800CD9E59 /* View Controllers */,
B73804ED22248ACF00CD9E59 /* Model Controller */,
);
path = Controllers;
sourceTree = "<group>";
};
B73804EC22248AC800CD9E59 /* View Controllers */ = {
isa = PBXGroup;
children = (
B7BA6EF621F7D4D6004A3C70 /* TaskListTableViewController.swift */,
B7BA6EF821F7D502004A3C70 /* TaskDetailTableViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
};
B73804ED22248ACF00CD9E59 /* Model Controller */ = {
isa = PBXGroup;
children = (
B73804E6221DCC8D00CD9E59 /* TaskController.swift */,
);
path = "Model Controller";
sourceTree = "<group>";
};
B73804EE22248B2900CD9E59 /* Views */ = {
isa = PBXGroup;
children = (
B73804E8221F729500CD9E59 /* SwitchTableViewCell.swift */,
);
path = Views;
sourceTree = "<group>";
};
B73804EF22248B4900CD9E59 /* Resources */ = {
isa = PBXGroup;
children = (
B7BA6EE521F7A442004A3C70 /* Main.storyboard */,
B7BA6EEB21F7A446004A3C70 /* Assets.xcassets */,
B7BA6EED21F7A446004A3C70 /* LaunchScreen.storyboard */,
B7BA6EF021F7A446004A3C70 /* Info.plist */,
);
path = Resources;
sourceTree = "<group>";
};
B7BA6ED521F7A442004A3C70 = {
isa = PBXGroup;
children = (
Expand All @@ -63,15 +122,10 @@
isa = PBXGroup;
children = (
B7BA6EE121F7A442004A3C70 /* AppDelegate.swift */,
B7BA6EF621F7D4D6004A3C70 /* TaskListTableViewController.swift */,
B7BA6EFA21F7D585004A3C70 /* CoreDataStack.swift */,
B761071D22136DDD001F79B6 /* Task + Convenience.swift */,
B7BA6EF821F7D502004A3C70 /* TaskDetailTableViewController.swift */,
B7BA6EE521F7A442004A3C70 /* Main.storyboard */,
B7BA6EEB21F7A446004A3C70 /* Assets.xcassets */,
B7BA6EED21F7A446004A3C70 /* LaunchScreen.storyboard */,
B7BA6EF021F7A446004A3C70 /* Info.plist */,
B7BA6EE821F7A442004A3C70 /* Task.xcdatamodeld */,
B73804EA22248AB600CD9E59 /* Model */,
B73804EB22248AC200CD9E59 /* Controllers */,
B73804EE22248B2900CD9E59 /* Views */,
B73804EF22248B4900CD9E59 /* Resources */,
);
path = Task;
sourceTree = "<group>";
Expand Down Expand Up @@ -147,6 +201,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B73804E7221DCC8E00CD9E59 /* TaskController.swift in Sources */,
B73804E9221F729500CD9E59 /* SwitchTableViewCell.swift in Sources */,
B7BA6EFB21F7D585004A3C70 /* CoreDataStack.swift in Sources */,
B7BA6EF721F7D4D6004A3C70 /* TaskListTableViewController.swift in Sources */,
B761071E22136DDD001F79B6 /* Task + Convenience.swift in Sources */,
Expand Down Expand Up @@ -300,7 +356,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = W53Z73CT67;
INFOPLIST_FILE = Task/Info.plist;
INFOPLIST_FILE = "$(SRCROOT)/Task/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -318,7 +374,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = W53Z73CT67;
INFOPLIST_FILE = Task/Info.plist;
INFOPLIST_FILE = "$(SRCROOT)/Task/Resources/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// TaskController.swift
// Task
//
// Created by Frank Martin on 2/20/19.
// Copyright © 2019 DevMtnStudent. All rights reserved.
//

import Foundation
import CoreData

class TaskController {

// Shared instance
static let shared = TaskController()

// Source of truth
var tasks: [Task] {

// Create the fetch request
let fetchRequest: NSFetchRequest<Task> = NSFetchRequest(entityName: "Task")
do {
// Return the results of the fetch request.
return try CoreDataStack.context.fetch(fetchRequest)
} catch {
print("There was an error fetching the Tasks: \(error)")
return []
}
}

func createTaskWith(_ name: String, _ notes: String?, _ due: Date?) {

// Initialize a new Task object
let _ = Task(name: name, notes: notes, due: due)
saveToPersistentStore()
}

func update(_ task: Task, name: String, notes: String?, due: Date?) {

// Set the tasks's properties to the parameters that were passed in
task.name = name
task.notes = notes
task.due = due

saveToPersistentStore()

}

func delete(_ task: Task) {

// Remove the task from the Managed Object Context
CoreDataStack.context.delete(task)
saveToPersistentStore()
}

func toggleIsComplete(for task: Task) {
task.isComplete = !task.isComplete
saveToPersistentStore()
}

func saveToPersistentStore() {
do {
try CoreDataStack.context.save()
} catch {
print("There was an error saving to the persistent store. \(error)")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// TaskDetailTableViewController.swift
// Task
//
// Created by Frank Martin Jr on 1/22/19.
// Copyright © 2019 DevMtnStudent. All rights reserved.
//

import UIKit

class TaskDetailTableViewController: UITableViewController {

// MARK: - Outlets

@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var dueTextField: UITextField!
@IBOutlet weak var notesTextView: UITextView!
@IBOutlet var datePicker: UIDatePicker!

// MARK: - Constants & Variables

var task: Task? {
didSet {
loadViewIfNeeded()
updateViews()
}
}

override func viewDidLoad() {
super.viewDidLoad()
dueTextField.inputView = datePicker
}

@IBAction func saveButtonTapped(_ sender: Any) {

// Unwrap the name text field and ensure that the string is not empty
guard let name = nameTextField.text,
!name.isEmpty
else { return }

// If we are in the detail view for an existing task, unwrap it
if let task = task {

// Update the task
TaskController.shared.update(task, name: name, notes: notesTextView.text, due: datePicker.date)
} else {

// Create a new task
TaskController.shared.createTaskWith(name, notesTextView.text, datePicker.date)
}

// Pop the detail vc off the navigation stack
self.navigationController?.popViewController(animated: true)
}

@IBAction func datePickerChaged(_ sender: UIDatePicker) {
dueTextField.text = "\(sender.date)"
}

func updateViews() {
guard let task = task else { return }
nameTextField.text = task.name
dueTextField.text = task.due != nil ? String(describing: task.due!) : ""

}
}
Loading