0

I honestly have know idea anymore how to fix this conversion issue.

This is my array:

var family = [
    ["Angelfish", "Butterflyfish", "Surgeonfish"],
    ["Manatees", "Dolphins", "Whales"],
    ["Rays", "Sharks"],
    ["Triggerfish", "Porcupinefish", "Pufferfish", "Boxfish", "Trumpetfish"],
    ["Sea Turtles"],
    ["Moray Eels"]
]

This is my action for the row selection:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let familyVC = FamilyVC()
    familyVC.customInit(familyIndex: indexPath.row, title: family[indexPath.row])
    self.navigationController?.pushViewController(familyVC, animated: true)
    tableView.deselectRow(at: indexPath, animated: true)
}

1 Answer 1

3

Have you flattened out that array to show all the fish, one on each row? Or do you have it broken down into sections.

If it's in sections, then you would have "Angelfish", "Butterflyfish", "Surgeonfish" in your first section, "Manatees", "Dolphins", "Whales" in the second, and so on. So you would find those in the array like this:

familyVC.customInit(familyIndex: indexPath.row, title: family[indexPath.section][indexPath.row])

If you just want to show all the fish, one per row, you could flatten out the array with

let allFish = family.flatMap { $0 }

then use the allFish array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.