Skip to content

Commit

Permalink
Fixed RestKit example
Browse files Browse the repository at this point in the history
RestKit example would crash when adding new entry
  • Loading branch information
David Chavez committed Feb 12, 2015
1 parent 32cf945 commit de82218
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

import UIKit

class RestKitTableViewController: CoreDataTableViewController {
class RestKitTableViewController: StackTableViewController {

//MARK: - Attributes

var data: SugarRecordResults?
internal let model: NSManagedObjectModel = {
let modelPath: NSString = NSBundle.mainBundle().pathForResource("Models", ofType: "momd")!
let model: NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: NSURL(fileURLWithPath: modelPath)!)!
return model
}()

//MARK: - Viewcontroller Lifecycle

Expand Down Expand Up @@ -42,15 +51,29 @@ class RestKitTableViewController: CoreDataTableViewController {
self.data = RestKitModel.all().sorted(by: "date", ascending: false).find()
}

override func dataCount() -> Int {
if (data == nil) { return 0 }
else { return data!.count }
}


//MARK: - Cell

override func configureCell(cell: UITableViewCell, indexPath: NSIndexPath) {
let formatter = NSDateFormatter()
formatter.dateFormat = "MMMM d yyyy - HH:mm:ss"
let model = self.data![indexPath.row] as RestKitModel
cell.textLabel!.text = model.name
cell.detailTextLabel!.text = formatter.stringFromDate(model.date)
cell.textLabel?.text = model.name
cell.detailTextLabel?.text = formatter.stringFromDate(model.date)
}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == .Delete) {
let model = self.data![indexPath.row] as RestKitModel
model.beginWriting().delete().endWriting()
self.fetchData()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}

override func cellIdentifier() -> String {
Expand Down

0 comments on commit de82218

Please sign in to comment.