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 trialAnjali Pasupathy
28,883 PointsWhy not use a helper method that you can call inside loadFirstChoice() and loadSecondChoice() to make the code more DRY?
Couldn't you use a nested function that passes the Choice parameter, like so?
func loadFirstChoice() {
if let page = page, firstChoice = page.firstChoice {
loadChoice(firstChoice)
}
}
func loadSecondChoice() {
if let page = page, secondChoice = page.secondChoice {
loadChoice(firstChoice)
}
}
func loadChoice(choice: Choice) {
let nextPage = choice.page
let pageController = PageController(page: nextPage)
navigationController?.pushViewController(pageController, animated: true)
}
Andrea Miotto
iOS Development Techdegree Graduate 23,357 PointsAndrea Miotto
iOS Development Techdegree Graduate 23,357 PointsYup I was thinking the same