Cannot subscript a value of type '[xxx]' with an argument of type '[xxx]'

Still toiling away with a cookbook app. I am at the third View Controller that displays the detail of a selected recipe. I am having trouble correctly getting the recipeStep.

Given the Struct of:

// MARK: - Recipe
struct Recipe: Decodable {
let recipeIndex: Int
let recipeName: String
let recipeTypes: RecipeType
}

// MARK: - RecipeType
struct RecipeType: Decodable {
let structured: [Structured]?
let unstructured: Unstructured?

}

// MARK: - Structured
struct Structured: Decodable {
let recipePartLabel: String?
let recipeIngredientsList: RecipeIngredientsList
let recipeStepsList: RecipeStepsList
}

// ... Cut out RecipeIngredientsList bit for brevity

// MARK: - RecipeStepsList
struct RecipeStepsList: Decodable {
let recipeStep: [RecipeStep]
}

// MARK: - RecipeStep
struct RecipeStep: Decodable {
let recipeStepName, recipeStepDescription: String
} 

When trying to get the recipeStep data for the RecipeStepsCell the autocomplete does not let me use dot notation to get down the struct path to recipeStep

Cannot subscript a value of type ‘[Structured]’ with an argument of type ‘[RecipeStepsList]’

// Get the sections and recipes from the CookbookModel
    func cookbookRetrieved(_ cookbook: Cookbook) {
        
        // Reference the array of the selectedChapter's index, and the nested array of recipes
        recipes = cookbook.chapters[selectedChapterIndex].recipes
        
        // For the selectedRecipe tableView, get the selectedRecipe and then the recipeType steps
        recipeStep = recipes[selectedRecipeIndex].recipeTypes.structured![recipeStepsList].recipeStep
        // STOP: Cannot subscript a value of type '[Structured]' with an argument of type '[RecipeStepsList]'

It looks like it’s expecting a number to indicate the index of the array like this:

recipeStep = recipes[selectedRecipeIndex].recipeTypes.structured![7]

I’m just using “7” as an example above but it needs to be something that evaluates to a number.

The error is happening because instead of a number, you have recipeStepsList which itself is an array. So it’s not a valid number!

Thanks Chris for looking at my problem,

I have put in a number e.g. [2] as you suggested, but now I get
Cannot assign value of type 'Structured' to type '[RecipeStep]'

I have popped in a breakpoint (and commented the offending line of code) as the app will segue to the RecipeViewController. However, if the offending line is uncommented out the app fails t build.
The app CookAlphaTwo is in GitHub, and I have invited you as a collaborator.

Really appreciate any guidance you may be able to provide.

Gong Xi Fa Chai.
I think my problem is somewhere in here, as numberofRow returns 0

// Add in the UITableViewDataSource stubs
extension RecipeViewController: UITableViewDataSource {
    
// Add in the numberOfRowsInSection
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

// Now that we have two table view we have to handle them by adding in a switch statement in order to determine the number of rows in each table, so create a var
var numberOfRow = 1

// Create switch and a case for each table
switch tableView {
case recipeStepsTable:
    numberOfRow = recipeStep.count
case tableOfRecipes:
    numberOfRow = recipes.count
default:
    print("Something went wrong with counting number of rows")
}

return numberOfRow

The solution was to

// Create property to hold the number of Parts in a recipe

var recipeParts = [Structured]()

Then in CookbookModelProtocol

recipeParts = recipes[selectedRecipeIndex].recipeTypes.structured!

This returned the count of recipeParts.

My next learning will be how to get access to the recipeStepsList so I can populate the table with the steps.