Add Array extensions

This commit is contained in:
Florian Gabach
2017-03-03 10:34:10 +01:00
parent 3c85e3a413
commit 88b67d62cc
2 changed files with 23 additions and 3 deletions
@@ -126,9 +126,7 @@ class OpenSourceViewController: UITableViewController {
reuseIdentifier: self.reuseIdentifier)
}
if let licences = self.downloadedLicence,
indexPath.row < licences.count {
let licence = licences[indexPath.row]
if let licence = self.downloadedLicence?.get(at: indexPath.row) {
cell?.configure(licence: licence)
}
@@ -0,0 +1,22 @@
//
// Array+Extensions.swift
// Pods
//
// Created by Florian Gabach on 03/03/2017.
//
//
import Foundation
extension Array {
/// Get an index safely
public func get(at index: Int) -> Element? {
guard index >= 0
&& index < count else {
return nil
}
return self[index]
}
}