diff --git a/Todoey.xcodeproj/project.pbxproj b/Todoey.xcodeproj/project.pbxproj index 423123ef..5a268849 100644 --- a/Todoey.xcodeproj/project.pbxproj +++ b/Todoey.xcodeproj/project.pbxproj @@ -7,17 +7,25 @@ objects = { /* Begin PBXBuildFile section */ + 0CE0D8C0BD1A47BF8F0B1D60 /* Pods_Todoey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1761A21657AB8618B197D056 /* Pods_Todoey.framework */; }; + 9D74BAA22469DDD7006E5DF5 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9D74BAA02469DDD7006E5DF5 /* DataModel.xcdatamodeld */; }; + 9D7DA83E246D064000AD882D /* CategoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D7DA83D246D064000AD882D /* CategoryViewController.swift */; }; EB2BE4FA239524DB00FB933B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2BE4F9239524DB00FB933B /* AppDelegate.swift */; }; - EB2BE4FE239524DB00FB933B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2BE4FD239524DB00FB933B /* ViewController.swift */; }; + EB2BE4FE239524DB00FB933B /* TodoListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB2BE4FD239524DB00FB933B /* TodoListViewController.swift */; }; EB2BE501239524DB00FB933B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB2BE4FF239524DB00FB933B /* Main.storyboard */; }; EB2BE503239524DC00FB933B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EB2BE502239524DC00FB933B /* Assets.xcassets */; }; EB2BE506239524DC00FB933B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EB2BE504239524DC00FB933B /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 0A17296F838C29D43D20A9E0 /* Pods-Todoey.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Todoey.release.xcconfig"; path = "Target Support Files/Pods-Todoey/Pods-Todoey.release.xcconfig"; sourceTree = ""; }; + 1761A21657AB8618B197D056 /* Pods_Todoey.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Todoey.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 9D74BAA12469DDD7006E5DF5 /* DataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = ""; }; + 9D7DA83D246D064000AD882D /* CategoryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryViewController.swift; sourceTree = ""; }; + 9FEE6652EA4BF2DDFEBFFA8E /* Pods-Todoey.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Todoey.debug.xcconfig"; path = "Target Support Files/Pods-Todoey/Pods-Todoey.debug.xcconfig"; sourceTree = ""; }; EB2BE4F6239524DB00FB933B /* Todoey.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Todoey.app; sourceTree = BUILT_PRODUCTS_DIR; }; EB2BE4F9239524DB00FB933B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - EB2BE4FD239524DB00FB933B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + EB2BE4FD239524DB00FB933B /* TodoListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListViewController.swift; sourceTree = ""; }; EB2BE500239524DB00FB933B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; EB2BE502239524DC00FB933B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; EB2BE505239524DC00FB933B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -29,17 +37,55 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0CE0D8C0BD1A47BF8F0B1D60 /* Pods_Todoey.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 7FED3DF95005E8AEE77E0ACE /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1761A21657AB8618B197D056 /* Pods_Todoey.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 9D74BA9B2469B4C9006E5DF5 /* Data Model */ = { + isa = PBXGroup; + children = ( + 9D74BAA02469DDD7006E5DF5 /* DataModel.xcdatamodeld */, + ); + path = "Data Model"; + sourceTree = ""; + }; + 9D74BA9C2469B4D3006E5DF5 /* Controllers */ = { + isa = PBXGroup; + children = ( + EB2BE4FD239524DB00FB933B /* TodoListViewController.swift */, + 9D7DA83D246D064000AD882D /* CategoryViewController.swift */, + ); + path = Controllers; + sourceTree = ""; + }; + B045CBD33A5C732FFFFAFB43 /* Pods */ = { + isa = PBXGroup; + children = ( + 9FEE6652EA4BF2DDFEBFFA8E /* Pods-Todoey.debug.xcconfig */, + 0A17296F838C29D43D20A9E0 /* Pods-Todoey.release.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; EB2BE4ED239524DB00FB933B = { isa = PBXGroup; children = ( EB2BE4F8239524DB00FB933B /* Todoey */, EB2BE4F7239524DB00FB933B /* Products */, + B045CBD33A5C732FFFFAFB43 /* Pods */, + 7FED3DF95005E8AEE77E0ACE /* Frameworks */, ); sourceTree = ""; }; @@ -55,11 +101,12 @@ isa = PBXGroup; children = ( EB2BE4F9239524DB00FB933B /* AppDelegate.swift */, - EB2BE4FD239524DB00FB933B /* ViewController.swift */, + 9D74BA9C2469B4D3006E5DF5 /* Controllers */, EB2BE4FF239524DB00FB933B /* Main.storyboard */, EB2BE502239524DC00FB933B /* Assets.xcassets */, EB2BE504239524DC00FB933B /* LaunchScreen.storyboard */, EB2BE507239524DC00FB933B /* Info.plist */, + 9D74BA9B2469B4C9006E5DF5 /* Data Model */, ); path = Todoey; sourceTree = ""; @@ -71,9 +118,11 @@ isa = PBXNativeTarget; buildConfigurationList = EB2BE50A239524DC00FB933B /* Build configuration list for PBXNativeTarget "Todoey" */; buildPhases = ( + 2FE5AE3D7C9EFC78B5C86DA9 /* [CP] Check Pods Manifest.lock */, EB2BE4F2239524DB00FB933B /* Sources */, EB2BE4F3239524DB00FB933B /* Frameworks */, EB2BE4F4239524DB00FB933B /* Resources */, + 15C4C9678707F997B8B479BC /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -130,12 +179,56 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 15C4C9678707F997B8B479BC /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Todoey/Pods-Todoey-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Todoey/Pods-Todoey-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Todoey/Pods-Todoey-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 2FE5AE3D7C9EFC78B5C86DA9 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Todoey-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ EB2BE4F2239524DB00FB933B /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EB2BE4FE239524DB00FB933B /* ViewController.swift in Sources */, + 9D7DA83E246D064000AD882D /* CategoryViewController.swift in Sources */, + EB2BE4FE239524DB00FB933B /* TodoListViewController.swift in Sources */, + 9D74BAA22469DDD7006E5DF5 /* DataModel.xcdatamodeld in Sources */, EB2BE4FA239524DB00FB933B /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -278,6 +371,7 @@ }; EB2BE50B239524DC00FB933B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 9FEE6652EA4BF2DDFEBFFA8E /* Pods-Todoey.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; @@ -287,7 +381,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.londonappbrewery.todoey-ios13.Todoey"; + PRODUCT_BUNDLE_IDENTIFIER = "com.masunomatiko.todoey-ios13.Todoey"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -296,6 +390,7 @@ }; EB2BE50C239524DC00FB933B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 0A17296F838C29D43D20A9E0 /* Pods-Todoey.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; @@ -305,7 +400,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = "com.londonappbrewery.todoey-ios13.Todoey"; + PRODUCT_BUNDLE_IDENTIFIER = "com.masunomatiko.todoey-ios13.Todoey"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -334,6 +429,19 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + 9D74BAA02469DDD7006E5DF5 /* DataModel.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + 9D74BAA12469DDD7006E5DF5 /* DataModel.xcdatamodel */, + ); + currentVersion = 9D74BAA12469DDD7006E5DF5 /* DataModel.xcdatamodel */; + path = DataModel.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = EB2BE4EE239524DB00FB933B /* Project object */; } diff --git a/Todoey.xcodeproj/project.xcworkspace/xcuserdata/satomari.xcuserdatad/UserInterfaceState.xcuserstate b/Todoey.xcodeproj/project.xcworkspace/xcuserdata/satomari.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..7556fae0 Binary files /dev/null and b/Todoey.xcodeproj/project.xcworkspace/xcuserdata/satomari.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Todoey.xcodeproj/xcuserdata/satomari.xcuserdatad/xcschemes/xcschememanagement.plist b/Todoey.xcodeproj/xcuserdata/satomari.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..a6e80f53 --- /dev/null +++ b/Todoey.xcodeproj/xcuserdata/satomari.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Todoey.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Todoey.xcworkspace/contents.xcworkspacedata b/Todoey.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..c0221ece --- /dev/null +++ b/Todoey.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Todoey/AppDelegate.swift b/Todoey/AppDelegate.swift index 9fbce18a..0d9000b0 100644 --- a/Todoey/AppDelegate.swift +++ b/Todoey/AppDelegate.swift @@ -1,12 +1,13 @@ // // AppDelegate.swift -// Destini +// Todoey // -// Created by Philipp Muellauer on 01/09/2015. -// Copyright (c) 2015 London App Brewery. All rights reserved. +// Created by Angela Yu on 16/11/2017. +// Copyright © 2017 Angela Yu. All rights reserved. // import UIKit +import CoreData @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -15,32 +16,45 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. + return true } - func applicationWillResignActive(_ application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - func applicationDidEnterBackground(_ application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } + func applicationWillTerminate(_ application: UIApplication) { - func applicationWillEnterForeground(_ application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + self.saveContext() } - - func applicationDidBecomeActive(_ application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + + // MARK: - Core Data stack + + lazy var persistentContainer: NSPersistentContainer = { + + let container = NSPersistentContainer(name: "DataModel") + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + return container + }() + + // MARK: - Core Data Saving support + + func saveContext () { + let context = persistentContainer.viewContext + if context.hasChanges { + do { + try context.save() + } catch { + + let nserror = error as NSError + fatalError("Unresolved error \(nserror), \(nserror.userInfo)") + } + } } - func applicationWillTerminate(_ application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } } - diff --git a/Todoey/Base.lproj/Main.storyboard b/Todoey/Base.lproj/Main.storyboard index 25a76385..6ad413b4 100644 --- a/Todoey/Base.lproj/Main.storyboard +++ b/Todoey/Base.lproj/Main.storyboard @@ -1,24 +1,118 @@ - + + - - + - - + + - - - + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Todoey/Controllers/CategoryViewController.swift b/Todoey/Controllers/CategoryViewController.swift new file mode 100644 index 00000000..4da1bff7 --- /dev/null +++ b/Todoey/Controllers/CategoryViewController.swift @@ -0,0 +1,105 @@ +// +// CategoryViewController.swift +// Todoey +// +// Created by 佐藤万莉 on 2020/05/14. +// Copyright © 2020 App Brewery. All rights reserved. +// + +import Foundation +import UIKit +import CoreData + +class CategoryViewController: UITableViewController { + override func viewDidLoad() { + super.viewDidLoad() + loadCategories() + } + + var category: String = "" + + var categoryArray = [Category]() + + let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return categoryArray.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryCell", for: indexPath) + + cell.textLabel?.text = categoryArray[indexPath.row].name + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + category = categoryArray[indexPath.row].name! + performSegue(withIdentifier: "goToItems", sender: nil) + + } + + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "goToItems" { + let todoVC = segue.destination as! TodoListViewController + if let indexPath = tableView.indexPathForSelectedRow { + todoVC.selectedCategory = categoryArray[indexPath.row] + } + } + } + + + + @IBAction func addButtonPressed(_ sender: UIBarButtonItem) { + var textField = UITextField() + + let alert = UIAlertController(title: "Add New Todoey category", message: "", preferredStyle: .alert) + + let action = UIAlertAction(title: "AddItem", style: .default) { (action) in + let newCategory = Category(context: self.context) + newCategory.name = textField.text! + + self.categoryArray.append(newCategory) + self.saveCategories() + self.tableView.reloadData() + + } + + alert.addTextField { (alertTextField) in + alertTextField.placeholder = "Create new category" + textField = alertTextField + } + + alert.addAction(action) + present(alert, animated: true, completion: nil) + + +// MARK: - Tableview Detasource Methods + +// MARK: - Tableview Delegate Methods + +// MARK: - Tableview Data Manipulation Methods + } + + func loadCategories(with request: NSFetchRequest = Category.fetchRequest()) { + + do { + categoryArray = try context.fetch(request) + } catch { + print(error) + } + tableView.reloadData() + } + + func saveCategories() { + do { + try context.save() + } catch { + print(error) + } + + } +} + + diff --git a/Todoey/Controllers/TodoListViewController.swift b/Todoey/Controllers/TodoListViewController.swift new file mode 100644 index 00000000..990c882c --- /dev/null +++ b/Todoey/Controllers/TodoListViewController.swift @@ -0,0 +1,152 @@ +// +// ViewController.swift +// Todoey +// +// Created by Philipp Muellauer on 02/12/2019. +// Copyright © 2019 App Brewery. All rights reserved. +// + +import UIKit +import CoreData + +class TodoListViewController: UITableViewController { + + var itemArray = [Item]() +// var itemArray = [ +// "Find Mike", +// "buy gyoza", +// "Done Swift course" +// ] + + var selectedCategory: Category? { + didSet{ + loadItems() + } + } + +// let defaults = UserDefaults.standard +// let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("Items.plist") + let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + +// print(dataFilePath) + +// loadItems() + + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return itemArray.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "TodoItemCell", for: indexPath) + + let item = itemArray[indexPath.row] + cell.textLabel?.text = item.title + + cell.accessoryType = item.done ? .checkmark : .none + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + itemArray[indexPath.row].done = !itemArray[indexPath.row].done + + saveItems() + + tableView.reloadData() + tableView.deselectRow(at: indexPath, animated: true) + } + + @IBAction func addButtonPressed(_ sender: UIBarButtonItem) { + + var textField = UITextField() + + let alert = UIAlertController(title: "Add New Todoey Item", message: "", preferredStyle: .alert) + + let action = UIAlertAction(title: "Add Item", style: .default) { (action) in + + let newItem = Item(context: self.context) + newItem.title = textField.text! + newItem.done = false + newItem.parentCategory = self.selectedCategory + self.itemArray.append(newItem) + + self.saveItems() + + self.tableView.reloadData() + } + + + + alert.addTextField { (alertTextField) in + alertTextField.placeholder = "Create new item" + textField = alertTextField + } + + alert.addAction(action) + present(alert, animated: true, completion: nil) + } + + func saveItems() { + + do { + try context.save() + + } catch { + print(error) + } + } + + func loadItems(with request: NSFetchRequest = Item.fetchRequest(), predicate: NSPredicate? = nil) { + + let categoryPredicate = NSPredicate(format: "parentCategory.name MATCHES %@", selectedCategory!.name!) + + if let additionalPredicate = predicate { + request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [categoryPredicate, additionalPredicate]) + } else { + request.predicate = categoryPredicate + } + + + do { + itemArray = try context.fetch(request) + } catch { + print(error) + } + tableView.reloadData() + + } + + +} + +//MARK: - Searchbar methods + +extension TodoListViewController: UISearchBarDelegate { + func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { + let request: NSFetchRequest = Item.fetchRequest() + + let predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchBar.text!) + + request.predicate = predicate + + let sortDescriptor = NSSortDescriptor(key: "title", ascending: true) + request.sortDescriptors = [sortDescriptor] + + loadItems(with: request) + + } + + func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { + loadItems() + DispatchQueue.main.async { + searchBar.resignFirstResponder() + } + + } +} diff --git a/Todoey/Data Model/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents b/Todoey/Data Model/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents new file mode 100644 index 00000000..bdefb3f3 --- /dev/null +++ b/Todoey/Data Model/DataModel.xcdatamodeld/DataModel.xcdatamodel/contents @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Todoey/ViewController.swift b/Todoey/ViewController.swift deleted file mode 100644 index 4a475a34..00000000 --- a/Todoey/ViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// ViewController.swift -// Todoey -// -// Created by Philipp Muellauer on 02/12/2019. -// Copyright © 2019 App Brewery. All rights reserved. -// - -import UIKit - -class ViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} -