1

I currently have

struct cellData {
    var opened = Bool()
    var title = String()
    var iconName = String()
    var sectionData = [Any]()
}

struct SectionData {
    var subTitle: String
    var iconName: String
}

And in another function I call:

let test = tableViewData[indexPath.section].sectionData[dataIndex]

print(test)

Which outputs:

SectionData(subTitle: "Terms", iconName: "")

How do I access the subTitle value because doing test.subTitle throws the following error:

Value of type 'Any' has no member 'subTitle'

2 Answers 2

6

This is because, in your line var sectionData = [Any](), you have defined the type as Any. So when you access it via tableViewData[indexPath.section], you get back the value as Any.

You should change var sectionData = [Any]() to var sectionData = [SectionData]()

Otherwise, once you get the value from tableViewData[indexPath.section], you can convert to SectionData and then access the value.

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

1 Comment

@JasonBiondo if this answer resolved your issue (the right answer), please don't forget to accept it (green tick it).
0

Change your sectionData array to an array of SectionData like so: var sectionData = [SectionData](). Once you do this, you'll able to access it by calling: tableViewData[indexPath.section].sectionData[dataIndex].subTitle

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.