diff --git a/WatchNotes WatchKit Extension/InterfaceController.swift b/WatchNotes WatchKit Extension/InterfaceController.swift index 5bd8d59..0c29f33 100644 --- a/WatchNotes WatchKit Extension/InterfaceController.swift +++ b/WatchNotes WatchKit Extension/InterfaceController.swift @@ -16,9 +16,9 @@ class InterfaceController: WKInterfaceController,NSFilePresenter { var notes :NSMutableArray? - override init(context: AnyObject?) { + override init() { // Initialize variables here. - super.init(context: context) + super.init() NSFileCoordinator.addFilePresenter(self) @@ -45,7 +45,7 @@ class InterfaceController: WKInterfaceController,NSFilePresenter { let fileCoordinator = NSFileCoordinator() var note :String? - fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: nil, error: nil) { (newURL :NSURL!) -> Void in + fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: [], error: nil) { (newURL :NSURL) -> Void in let savedData = NSData(contentsOfURL: newURL) @@ -58,9 +58,9 @@ class InterfaceController: WKInterfaceController,NSFilePresenter { self.tableView?.setNumberOfRows(self.notes!.count, withRowType: "NotesTableRowController") - for (index,value) in enumerate(self.notes!) { + for (index,value) in (self.notes!).enumerate() { - let row = self.tableView?.rowControllerAtIndex(index) as NotesTableRowController + let row = self.tableView?.rowControllerAtIndex(index) as! NotesTableRowController row.noteTitleLabel?.setText(value as? String) diff --git a/WatchNotes.xcodeproj/project.pbxproj b/WatchNotes.xcodeproj/project.pbxproj index ec2010c..ad2b258 100644 --- a/WatchNotes.xcodeproj/project.pbxproj +++ b/WatchNotes.xcodeproj/project.pbxproj @@ -314,6 +314,8 @@ 34E77AC21A211A150083241E /* Project object */ = { isa = PBXProject; attributes = { + LastSwiftMigration = 0710; + LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0620; ORGANIZATIONNAME = "AzamSharp Consulting LLC"; TargetAttributes = { diff --git a/WatchNotes/Base.lproj/Main.storyboard b/WatchNotes/Base.lproj/Main.storyboard index 8f5fc00..540989a 100644 --- a/WatchNotes/Base.lproj/Main.storyboard +++ b/WatchNotes/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - + - + + + @@ -10,14 +12,20 @@ + + + + + + @@ -25,7 +33,16 @@ - + + + + + + + + + + @@ -45,11 +62,13 @@ + + @@ -108,6 +128,7 @@ + diff --git a/WatchNotes/NotesTableViewController.swift b/WatchNotes/NotesTableViewController.swift index 1dd750e..94d724d 100644 --- a/WatchNotes/NotesTableViewController.swift +++ b/WatchNotes/NotesTableViewController.swift @@ -13,12 +13,24 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile var notes :NSMutableArray = NSMutableArray() var fileCoordinator = NSFileCoordinator() + @IBOutlet weak var editButton: UIBarButtonItem! + + //When 'Edit' button is click in NavBar to rearrange table + @IBAction func beginEditing(sender: AnyObject) { + if(!self.editing){ + editButton.title = "Done" + }else{ + editButton.title = "Edit" + } + self.editing = !self.editing + } + override func viewDidLoad() { super.viewDidLoad() - // delete all existing notes + // delete all existing notes deleteAllNotes() // populate the notes and update the tableView @@ -43,7 +55,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile private func populateNotes() { // get the notes array - fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: nil, error: nil) { (newURL :NSURL!) -> Void in + fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: [], error: nil) { (newURL :NSURL) -> Void in let savedData = NSData(contentsOfURL: newURL) @@ -52,7 +64,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile } else { - self.notes = NSKeyedUnarchiver.unarchiveObjectWithData(savedData!) as NSMutableArray + self.notes = NSKeyedUnarchiver.unarchiveObjectWithData(savedData!) as! NSMutableArray } } @@ -61,7 +73,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile private func saveNote(note :String) { // write note into the notes array - fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: nil, error: nil) { ( newURL :NSURL!) -> Void in + fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: [], error: nil) { ( newURL :NSURL) -> Void in self.notes.addObject(note) @@ -74,7 +86,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile private func updateNotes() { // write note into the notes array - fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: nil, error: nil) { ( newURL :NSURL!) -> Void in + fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: [], error: nil) { ( newURL :NSURL) -> Void in let saveData = NSKeyedArchiver.archivedDataWithRootObject(self.notes) let success = saveData.writeToURL(newURL, atomically: true) @@ -84,7 +96,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile private func deleteAllNotes() { - fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: nil, error: nil) { ( newURL :NSURL!) -> Void in + fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: [], error: nil) { ( newURL :NSURL) -> Void in self.notes = NSMutableArray() // writing an empty array @@ -142,7 +154,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile let cell = tableView.dequeueReusableCellWithIdentifier("NoteCell", forIndexPath: indexPath) as UITableViewCell - var note = self.notes[indexPath.row] as String + var note = self.notes[indexPath.row] as! String cell.textLabel?.text = note @@ -153,6 +165,16 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile return true; } + override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool { + return true} + + override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) { + var itemToMove = notes[fromIndexPath.row] + notes.removeObjectAtIndex(fromIndexPath.row) + notes.insertObject(itemToMove, atIndex: toIndexPath.row) + updateNotes() + } + override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if editingStyle == UITableViewCellEditingStyle.Delete { @@ -167,7 +189,7 @@ class NotesTableViewController: UITableViewController,UITextFieldDelegate,NSFile func textFieldDidEndEditing(textField: UITextField) { - saveNote(textField.text) + saveNote(textField.text!) // reload table self.tableView.reloadData() diff --git a/WatchNotes/ViewController.swift b/WatchNotes/ViewController.swift index 1825c14..f07df43 100644 --- a/WatchNotes/ViewController.swift +++ b/WatchNotes/ViewController.swift @@ -44,7 +44,7 @@ class ViewController: UIViewController,NSFilePresenter { let fileCoordinator = NSFileCoordinator() - fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: nil, error: nil) { ( newURL :NSURL!) -> Void in + fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: [], error: nil) { ( newURL :NSURL) -> Void in self.notes = NSMutableArray() // writing an empty array @@ -61,7 +61,7 @@ class ViewController: UIViewController,NSFilePresenter { let note = self.noteTextField?.text // get the notes array - fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: nil, error: nil) { (newURL :NSURL!) -> Void in + fileCoordinator.coordinateReadingItemAtURL(presentedItemURL!, options: [], error: nil) { (newURL :NSURL) -> Void in let savedData = NSData(contentsOfURL: newURL) @@ -77,7 +77,7 @@ class ViewController: UIViewController,NSFilePresenter { // write note into the notes array - fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: nil, error: nil) { ( newURL :NSURL!) -> Void in + fileCoordinator.coordinateWritingItemAtURL(presentedItemURL!, options: [], error: nil) { ( newURL :NSURL) -> Void in self.notes?.addObject(note!)