Skip to content

Instantly share code, notes, and snippets.

@NikKovIos
Last active February 10, 2018 08:23
Show Gist options
  • Save NikKovIos/78fc01e7230c8081706802a5f9f8f364 to your computer and use it in GitHub Desktop.
Save NikKovIos/78fc01e7230c8081706802a5f9f8f364 to your computer and use it in GitHub Desktop.
Realm prevent crash for `Index x is out of bounds (must be less than x)`
// Use
if indexPath.row < arrayOfObjects.count {
cell.label.text = arrayOfObjects[indexPath.row]
} else {
// Handle non-existing object here
}
// Example:
if let wheel = wheel, let row = indexPath?.row, row < wheel.comments.count {
let comment = wheel.comments[row]
nameLabel.text = comment.userName
bodyLabel.text = comment.text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment