Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Improve objectAtIndexPath safety + change file name
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Nov 18, 2015
1 parent d12928e commit 7a88d1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/DataSource.swift → Source/DATASource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ public class DATASource: NSObject {
- returns: The object at a given index path in the fetch results.
*/
public func objectAtIndexPath(indexPath: NSIndexPath) -> NSManagedObject? {
return self.fetchedResultsController.objectAtIndexPath(indexPath) as? NSManagedObject ?? nil
if self.fetchedResultsController.fetchedObjects?.count > 0 {
return self.fetchedResultsController.objectAtIndexPath(indexPath) as? NSManagedObject ?? nil
}

return nil
}

/**
Expand Down Expand Up @@ -554,12 +558,12 @@ extension DATASource: NSFetchedResultsControllerDelegate {

private func configureCell(cell: UIView, indexPath: NSIndexPath) {
var item: NSManagedObject?

let rowIsInsideBounds = indexPath.row < self.fetchedResultsController.fetchedObjects?.count
if rowIsInsideBounds {
item = self.fetchedResultsController.objectAtIndexPath(indexPath) as? NSManagedObject
}

if let item = item {
if let _ = self.tableView, configuration = self.tableConfigurationBlock {
configuration(cell: cell as! UITableViewCell, item: item, indexPath: indexPath)
Expand Down

0 comments on commit 7a88d1a

Please sign in to comment.