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 a Story Creating an Adventure

Hello guys!! I have a question i started yesterday doing the Interactive Story App but today i did the update on Xcode

which it was Swift 3 to my surprise is been a headache since I am new in this i had so many errors even though I am writing the code exactly as Pasan does it in the following code the compiler is giving me error because it says that addChoide is unuse. Can someone help me and what can I do? Thank you

struct Adventure { static var story: Page { let returnTrip = Page(story: .ReturnTrip) let touchdown = returnTrip.addChoice("Stop and Investigate", story: .TouchDown) let homeward = returnTrip.addChoice("Continue Home to Earth", story: .Homeward) let rover = touchdown.addChoice("Explore the Rover", story: .Rover) let crate = touchdown.addChoice("Open the Crate", story: .Crate)

    homeward.addChoice("Head back to Mars", page: touchdown)
    let home = homeward.addChoice("Continue Home to Earth", story: .Home)

    let cave = rover.addChoice("Explore the Coordinates", story: .Cave)
    rover.addChoice("Return to Earth", page: home)

    cave.addChoice("Continue towards faint light", story: .Droid)
    cave.addChoice("Refill the ship and explore the rover", page: rover)

    crate.addChoice("Explore the Rover", page: rover)
    crate.addChoice("Use the key", story: .Monster)

    return returnTrip
}

}

4 Answers

Ronnie Stanley
Ronnie Stanley
4,842 Points

You should be using Xcode 7 until the courses have been updated for Xcode 8 and Swift 3

Gruff Vaughan
Gruff Vaughan
11,073 Points

I had this headache, until I played around and found under 'Build Settings' a dropdown for 'Use Legacy Swift Language Version'.

Change this to 'Yes' and your code will compile.

Thanks Gruff Vaughan what i did was i download Xcode 7.3 because it was going to be a big headache!!!

Thank you!! =)

Thomas Hugo
Thomas Hugo
5,457 Points

The biggest change I've noticed with Swift 3 // Xcode 8 that causes issues with old code is referenced here, specifically where it mentions "If a parameter has an argument label, the argument must be labeled when you call the function". This contrasts the Swift 2 // Xcode 7 practice of omitting the first parameter label.

In this particular case, you would simply need to add the first parameter label "title" each time the "addChoice" method is called.

So instead of "let touchdown = returnTrip.addChoice("Stop and Investigate", story: .TouchDown)" you would add "title: " so it reads "let touchdown = returnTrip.addChoice(title: "Stop and Investigate", story: .TouchDown)".