How about dateArray[4]
, seems straightforward to me. Array indexes are 0-based in Swift.
You could declare a function like so:
extension Array {
func getElement(position: Int) -> Element {
guard self.count > 0, position > 0, position <= self.count else {
fatalError("Error")
}
return self[position - 1]
}
}
And you could use it like so:
dateArray.getElement(position: 5) //"05.09.2018 05:44:00"
dateArray.getElement(position: 10) //"10.09.2018 06:09:00"
solved Swift get from string array