Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build an Interactive Story App with Swift Creating a Story Creating an Adventure

I 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

30,362 Points

You 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.