Reputation: 301
I want know the number of Array elements at compile time:
let sections = ["A","B","C"]
// I want fill later this Array with Arrays of type Product
var productsInSection = [[Product]](count:number of Array elements from sections array, repeatedValue:[])
my question is what I can use for: "number of Array elements from sections array" so I don't must have a look, if I change anytime
let sections = ["A","B","C","D"]
Upvotes: 0
Views: 169
Reputation: 51911
I don't understand why you need "compile time".
But I think count
property is sufficient for what you want:
let sections = ["A","B","C"]
var productsInSection = [[Product]](count:sections.count, repeatedValue:[])
Added to answer the comment
For example:
private let _indexSectionTitles = ["A","B","C","D","E","F","G","H","I","J","K","L","M", "N","O","P","Q","R","S","T","U","V","W","X","Y","Z", "Ä","Ö","Ü", "#" ]
class MyClass{
let indexSectionTitles = _indexSectionTitles
var productsInSection = [[GlobalProduct]](count: _indexSectionTitles.count, repeatedValue: [])
}
Upvotes: 1