Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCurtis Stilwell
17,750 PointsI don't understand how the pages are linked together. Perhaps someone can dumb it down for me.
I don't understand how these two pages (return trip and touchdown) are linked together at all.
struct Adventure {
static var story: Page {
let returnTrip = Page(story: .returnTrip)
let touchdown = returnTrip.addChoiceWith(title: "Stop and Investigate", story: .touchDown)
return returnTrip
}
}
Shouldn't only the first page be linked since it is returning trip and not touchdown or an array of both? Does function below somehow allow it to be linked together.
func addChoiceWith(title: String, story:Story) -> Page { let page = Page(story:story) return addChoiceWith(title: title, page: page) }
Everything else in this tutorial I understand except this.
1 Answer
JLN CRML
30,362 PointsYou are basically creating a computed property called story, which code will be exectuted when you call it. The property is of type Page. The Page class has a method which you can use to add a choice to the page, which is going to be stored in the instance and can be read afterwards. All the linked properties / choices are also of type page, which you can use again in order to display a new ViewController.