I have a data model that stores specific extreme-sports information. This data is displayed in a tableView, where the cells (extreme sport tricks) can be tapped to view all the details in a Details VC. Part of these details is an optional 'related' section, which can be defined as part of the model.
Example - Table Cell may read "Kickflip" (a skateboarding trick). I can associate "Ollie" and "360-flip" (two more skateboarding tricks) to the Kickflip model's related section.
I want these two related terms (Ollie and 360-flip) clickable so that instead of the user reading 'Kickflip' details, they can read the definition of either Ollie or 360-flip.
My question here is how can I get the 'related' items to refresh the data to the specific term.
Here is my model:
struct ExtremeSportsData {
static func getAllSportsTerms() -> [ExtremeSportsTermsWithSectionHeaders] {
return [
ExtremeSportsTermsWithSectionHeaders(sectionName: "A", sectionObjects: [
ExtremeSportsTermsModel(term: "Acid Drop", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: nil),
ExtremeSportsTermsModel(term: "Alpha Flip", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: nil),
ExtremeSportsTermsModel(term: "Axle Stall", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: ["Ollie"])
]),
ExtremeSportsTermsWithSectionHeaders(sectionName: "O", sectionObjects: [
ExtremeSportsTermsModel(term: "Ollie", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: ["Shuvit"]),
ExtremeSportsTermsModel(term: "Overturn", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: ["Acid Drop", "Alpha Flip"])
]),
ExtremeSportsTermsWithSectionHeaders(sectionName: "S", sectionObjects: [
ExtremeSportsTermsModel(term: "Shuvit", definition: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", relatedTerms: ["Ollie", "Axle Stall", "Overturn"])
])
]
}
}
Once a cell is tapped, the information on the DetailVC gets displayed in a Collection View. I want the related terms (if there are any!) to update the data to that specific term. As you can see in my data above - if the user taps on Ollie, they will have Shuvit as a related term. That can be clicked to read the Shuvit definition & information.
My thought process for the UI was to use Contains(String), however this solution does not work IF there is a typo in the data.. (and my code below is not perfect)
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let specificRelatedTerm = receivedSportTerm!.relatedTerms![indexPath.item]
if receivedSportTerm!.term.contains(specificRelatedTerm) {
print("Yes - Related")
}
else {
print("No - Not related")
}
}
How can I set up "relationships" between data, so that I can tap buttons in a UI to update information based on the relationships?
I will be happy to clarify any of the above... Something is telling me I did not word this as good as I could have, but any help is appreciated thank you.