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
6 changes: 6 additions & 0 deletions ToDoList.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@
TargetAttributes = {
954D24811B7A2DDA00DD9E4E = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0830;
};
954D24961B7A2DDA00DD9E4E = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0830;
TestTargetID = 954D24811B7A2DDA00DD9E4E;
};
};
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ToDoList/AddToDoItemViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions ToDoList/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ 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
}
return true
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
stateController.save()
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
stateController.save()
}
}
Expand Down
10 changes: 5 additions & 5 deletions ToDoList/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
8 changes: 4 additions & 4 deletions ToDoList/TableViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
}
8 changes: 4 additions & 4 deletions ToDoList/TableViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}
18 changes: 9 additions & 9 deletions ToDoList/ToDoItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ToDoList/ToDoItemCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions ToDoList/ToDoListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}

Expand Down
2 changes: 1 addition & 1 deletion ToDoListTests/ToDoListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Expand Down