diff --git a/README.md b/README.md index 39dfb05..795cc6e 100644 --- a/README.md +++ b/README.md @@ -62,14 +62,22 @@ Hooking up your table view to your `Task` model and making your UITableView reac **Swift:** ```swift -let request: NSFetchRequest = NSFetchRequest(entityName: "Task") -request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)] +lazy var dataSource: DATASource = { + let request: NSFetchRequest = NSFetchRequest(entityName: "Task") + request.sortDescriptors = [NSSortDescriptor(key: "title", ascending: true)] -let dataSource = DATASource(tableView: self.tableView, cellIdentifier: "Cell", fetchRequest: request, mainContext: self.dataStack.mainContext, configuration: { cell, item, indexPath in - cell.textLabel?.text = item.valueForKey("title") as? String -}) + let dataSource = DATASource(tableView: self.tableView, cellIdentifier: "Cell", fetchRequest: request, mainContext: self.dataStack.mainContext, configuration: { cell, item, indexPath in + cell.textLabel?.text = item.valueForKey("title") as? String + }) -tableView.dataSource = dataSource + return dataSource +}() + +override func viewDidLoad() { + super.viewDidLoad() + + self.tableView.dataSource = self.dataSource +} ``` **Objective-C:**