This file contains hidden or 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
| // | |
| // ViewController.swift | |
| // WhatFlower | |
| // | |
| // Created by Greg Eales on 17/10/20. | |
| // | |
| import UIKit | |
| // TODDO: Add to .plist |
This file contains hidden or 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
| // App Delegate | |
| import CoreData | |
| func applicationWillTerminate(_ application: UIApplication) { | |
| self.saveContext() | |
| } | |
| // MARK: - Core Data stack | |
| lazy var persistentContainer: NSPersistentContainer = { |
This file contains hidden or 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
| // Mark "Item" struct as Codable | |
| var itemArray: [Item] = [] | |
| let dataFilePath = | |
| FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
| .first? | |
| .appendingPathComponent("Items.plist") | |
| func loadModel() { | |
| if let data = try? Data(contentsOf: dataFilePath!) { |
This file contains hidden or 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
| // Controller | |
| let defaults = UserDefaults.standard | |
| // Reading | |
| if let items = defaults.array(forKey: "TodoListArray") as? [String] { | |
| itemArray = items | |
| } | |
| else { | |
| itemArray = [] |
This file contains hidden or 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
| @IBAction func addButtonPressed(_ sender: UIBarButtonItem) { | |
| let alert = UIAlertController(title: "Add New Todoey Item", message: "", preferredStyle: .alert) | |
| var textField: UITextField? = nil | |
| let action = UIAlertAction(title: "Add Item", style: .default) { (action) in | |
| if let safeTextField = textField { | |
| print(safeTextField.text ?? "") | |
| } | |
| } | |
This file contains hidden or 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
| 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) | |
| cell.textLabel?.text = itemArray[indexPath.row] | |
| return cell | |
| } |
This file contains hidden or 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
| // App Delegate | |
| import IQKeyboardManagerSwift | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| IQKeyboardManager.shared.enable = true | |
| IQKeyboardManager.shared.enableAutoToolbar = false | |
| return true | |
| } |
This file contains hidden or 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
| // App Deleagate | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| FirebaseApp.configure() | |
| _ = Firestore.firestore() | |
| return true | |
| } | |
| // Controller | |
| // Init Firestore |
This file contains hidden or 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
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Register XIB for custom cell | |
| tableView.register(UINib(nibName: K.cellNibName, bundle: nil), forCellReuseIdentifier: K.cellIdentifier) | |
| } |
This file contains hidden or 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
| // App Delegate | |
| import Firebase | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool | |
| { | |
| FirebaseApp.configure() | |
| return true | |
| } | |
| // Register User Controller |