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 trial

iOS Build an Interactive Story App with Swift 2 Creating the User Interface Programmatically Making a Choice

Danny Kilkenny
Danny Kilkenny
4,507 Points

How does it select the correct button

In the Build an Interactive Story App (Making a Choice) section, I'm having trouble understanding how the code that he uses picks the correct titles such as "stop and investigate" instead of any of the other choices.

Thanks

1 Answer

Jeroen de Vrind
Jeroen de Vrind
29,772 Points

Hi Danny, In the Adventure struct the titles, named choices, are added to the story pages. Every page class has a firstChoice and secondChoice that can be set or can be nil. In the viewDidLoad() method of the PageController class these firstChoice and secondChoice of the page are set to the title of the button. firstChoice = page.firstChoice in which page is the Page object.