I want to enforce (compile time) array with 5 elements of a particular type
I couldn't find a solution so resorted to a workaround by creating a tuple
(This is abusive I know)
typealias FiveElementArray = (MyType,MyType,MyType,MyType,MyType) // mock array by using typed tuple
It works for my needs - until I need to access an element by index at runtime.
For instance:
var DB = FiveElementArray // the tuple of 5 elements
tableView(tableView : UITableView,cellForRowAtIndexPath:indexPath) -> UITableViewCell {
// would like to populate with the value at index
DB[indexpath.row] // no such syntax for tuples
}
So how can I use a proper swift Array with statically typed length
letinstead?The collection will be immutable... I would guess that means that you can not change it anymore => fixed length?!