I am trying to display a tabular representation of categories with each category having its own set of categories.
For example, the main categories are food, entertainment, leisure, as well as in the food section of the table, Mexican food, Asian cuisine, etc. displayed in this section.
However, I ran into this error:
Cannot index a value of type '[(String)]?' with an index of type 'Int'
Here is my code:
var categoryDictionary = [String:[String]]();
var categoriesList = ["Food", "Entertainment", "Recreation", "Shopping", "Transport", "Post Office"]
var foodCategories = [String]();
var entertainmentCategories = [String]();
var recreationCategories = [String]();
var shoppingCategories = [String]();
var transportCategories = [String]();
var lodgingCategories = [String]();
var librariesCategories = [String]();
var banksCategories = [String]();
var postOfficeCategories = [String]();
Here is an example of adding an array and adding the key value "Food" to the foodCategory array
func setupCategoryFood() {
var asianFood = "Asian Food"
var mexicanFood = "Mexican Food"
var fastFood = "Fast Food"
var MiddleEasternFood = "Middle Eastern Food"
foodCategories.append(asianFood);
foodCategories.append(mexicanFood);
foodCategories.append(fastFood);
foodCategories.append(MiddleEasternFood);
categoryDictionary["Food"] = foodCategories;
}
and then...
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("myCell") as! UITableViewCell;
var sectionTitle = categoriesList[indexPath.section]
var sectionArray = categoryDictionary[sectionTitle];
var itemInArray = sectionArray[indexPath.row];
return cell
}
I get an error when I try to set a variable to equal an element inside an array with given indexpath.row:
'Can't tune a value of type' [(String)]? 'with an index of type' Int '
, , .