diff --git a/ToDoList.xcodeproj/project.pbxproj b/ToDoList.xcodeproj/project.pbxproj index 2c5db07..b8fd73c 100644 --- a/ToDoList.xcodeproj/project.pbxproj +++ b/ToDoList.xcodeproj/project.pbxproj @@ -181,9 +181,11 @@ TargetAttributes = { 954D24811B7A2DDA00DD9E4E = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 0830; }; 954D24961B7A2DDA00DD9E4E = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 0830; TestTargetID = 954D24811B7A2DDA00DD9E4E; }; }; @@ -371,6 +373,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.purecreek.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -382,6 +385,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.purecreek.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -401,6 +405,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.purecreek.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ToDoList.app/ToDoList"; }; name = Debug; @@ -417,6 +422,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.purecreek.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ToDoList.app/ToDoList"; }; name = Release; diff --git a/ToDoList/AddToDoItemViewController.swift b/ToDoList/AddToDoItemViewController.swift index 7135444..40279bc 100644 --- a/ToDoList/AddToDoItemViewController.swift +++ b/ToDoList/AddToDoItemViewController.swift @@ -15,14 +15,14 @@ class AddToDoItemViewController: UIViewController { var stateController: StateController? - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - guard let tappedButton = sender as? UIBarButtonItem where tappedButton != cancelButton else { + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + guard let tappedButton = sender as? UIBarButtonItem, tappedButton != cancelButton else { return; } guard let text = nameTextField.text else { return } - let todoItem = ToDoItem(name: text, completed: false, creationDate: NSDate()) + let todoItem = ToDoItem(name: text, completed: false, creationDate: Date()) stateController?.addItem(todoItem) } diff --git a/ToDoList/AppDelegate.swift b/ToDoList/AppDelegate.swift index a8fc973..8ee65dc 100644 --- a/ToDoList/AppDelegate.swift +++ b/ToDoList/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? let stateController = StateController() - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if let navigationController = window?.rootViewController as? UINavigationController, let toDoListTableViewController = navigationController.viewControllers.first as? ToDoListTableViewController { toDoListTableViewController.stateController = stateController @@ -22,11 +22,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { stateController.save() } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { stateController.save() } } diff --git a/ToDoList/StateController.swift b/ToDoList/StateController.swift index c434a47..a9bc298 100644 --- a/ToDoList/StateController.swift +++ b/ToDoList/StateController.swift @@ -9,21 +9,21 @@ import Foundation class StateController { - static let itemsFilePath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! + "/items.txt" + static let itemsFilePath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + "/items.txt" - private(set) var items: [ToDoItem] = { - if let items = NSKeyedUnarchiver.unarchiveObjectWithFile(itemsFilePath) as? [ToDoItem] { + fileprivate(set) var items: [ToDoItem] = { + if let items = NSKeyedUnarchiver.unarchiveObject(withFile: itemsFilePath) as? [ToDoItem] { return items } else { return [ToDoItem]() } }() - func addItem(item: ToDoItem) { + func addItem(_ item: ToDoItem) { items.append(item) } func save() { NSKeyedArchiver.archiveRootObject(self.items, toFile: StateController.itemsFilePath) } -} \ No newline at end of file +} diff --git a/ToDoList/TableViewDataSource.swift b/ToDoList/TableViewDataSource.swift index 4ca9844..815b88a 100644 --- a/ToDoList/TableViewDataSource.swift +++ b/ToDoList/TableViewDataSource.swift @@ -20,16 +20,16 @@ class TableViewDataSource: NSObject { extension TableViewDataSource: UITableViewDataSource { - func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return stateController.items.count } - func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let toDoItem = stateController.items[indexPath.row] - let cell = tableView.dequeueReusableCellWithIdentifier(ToDoItemCell.identifier, forIndexPath: indexPath) as! ToDoItemCell + let cell = tableView.dequeueReusableCell(withIdentifier: ToDoItemCell.identifier, for: indexPath) as! ToDoItemCell cell.name = toDoItem.name cell.completed = toDoItem.completed return cell } -} \ No newline at end of file +} diff --git a/ToDoList/TableViewDelegate.swift b/ToDoList/TableViewDelegate.swift index 8dbde3e..6687889 100644 --- a/ToDoList/TableViewDelegate.swift +++ b/ToDoList/TableViewDelegate.swift @@ -20,11 +20,11 @@ class TableViewDelegate: NSObject { extension TableViewDelegate: UITableViewDelegate { - func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { - tableView.deselectRowAtIndexPath(indexPath, animated: false) + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: false) let tappedItem = stateController.items[indexPath.row] tappedItem.completed = !tappedItem.completed - tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.None) + tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.none) } -} \ No newline at end of file +} diff --git a/ToDoList/ToDoItem.swift b/ToDoList/ToDoItem.swift index f9b4ddd..4460ab5 100644 --- a/ToDoList/ToDoItem.swift +++ b/ToDoList/ToDoItem.swift @@ -10,25 +10,25 @@ import Foundation class ToDoItem: NSObject, NSCoding { let name: String - let creationDate: NSDate + let creationDate: Date var completed: Bool - init(name: String, completed: Bool, creationDate: NSDate) { + init(name: String, completed: Bool, creationDate: Date) { self.name = name self.completed = completed self.creationDate = creationDate } required init?(coder aDecoder: NSCoder) { - name = aDecoder.decodeObjectForKey(Keys.Name.rawValue) as! String - completed = aDecoder.decodeObjectForKey(Keys.Completed.rawValue) as! Bool - creationDate = aDecoder.decodeObjectForKey(Keys.CreationDate.rawValue) as! NSDate + name = aDecoder.decodeObject(forKey: Keys.Name.rawValue) as! String + completed = aDecoder.decodeObject(forKey: Keys.Completed.rawValue) as! Bool + creationDate = aDecoder.decodeObject(forKey: Keys.CreationDate.rawValue) as! Date } - func encodeWithCoder(aCoder: NSCoder) { - aCoder.encodeObject(name, forKey: Keys.Name.rawValue) - aCoder.encodeObject(completed, forKey: Keys.Completed.rawValue) - aCoder.encodeObject(creationDate, forKey: Keys.CreationDate.rawValue) + func encode(with aCoder: NSCoder) { + aCoder.encode(name, forKey: Keys.Name.rawValue) + aCoder.encode(completed, forKey: Keys.Completed.rawValue) + aCoder.encode(creationDate, forKey: Keys.CreationDate.rawValue) } enum Keys: String { diff --git a/ToDoList/ToDoItemCell.swift b/ToDoList/ToDoItemCell.swift index 5d2f090..1648ba1 100644 --- a/ToDoList/ToDoItemCell.swift +++ b/ToDoList/ToDoItemCell.swift @@ -20,9 +20,9 @@ class ToDoItemCell: UITableViewCell { var completed: Bool = false { didSet { if (completed) { - accessoryType = UITableViewCellAccessoryType.Checkmark + accessoryType = UITableViewCellAccessoryType.checkmark } else { - accessoryType = UITableViewCellAccessoryType.None; + accessoryType = UITableViewCellAccessoryType.none; } } } diff --git a/ToDoList/ToDoListTableViewController.swift b/ToDoList/ToDoListTableViewController.swift index b44553c..af251e8 100644 --- a/ToDoList/ToDoListTableViewController.swift +++ b/ToDoList/ToDoListTableViewController.swift @@ -22,19 +22,19 @@ class ToDoListTableViewController: UITableViewController { } } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) tableView.reloadData() } - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - if let navigationController = segue.destinationViewController as? UINavigationController, + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if let navigationController = segue.destination as? UINavigationController, let addToDoItemViewController = navigationController.viewControllers.first as? AddToDoItemViewController { addToDoItemViewController.stateController = stateController } } - @IBAction func unwindToList(segue: UIStoryboardSegue) { + @IBAction func unwindToList(_ segue: UIStoryboardSegue) { } diff --git a/ToDoListTests/ToDoListTests.swift b/ToDoListTests/ToDoListTests.swift index 9031ec2..47323a8 100644 --- a/ToDoListTests/ToDoListTests.swift +++ b/ToDoListTests/ToDoListTests.swift @@ -28,7 +28,7 @@ class ToDoListTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } }