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 trialAndrea Miotto
iOS Development Techdegree Graduate 23,357 PointsResult of call to 'addChoice(title:page:) is unused
Maybe I have a new versione of Xcode, but addChoice() return a Page type. When we call addChoice() like this:
homeward.addChoice(title: "Head back to Mars", page: touchdown)
I have the warning:
Result of call to 'addChoice(title:page:) is unused
Is there a better way? I don't like to have warnings :P
1 Answer
Michael Hulet
47,913 PointsIf it's warning you that you don't use the result, you can silence that warning by assigning it to an underscore constant, like this:
let _ = homeward.addChoice(title: "Head back to Mars", page: touchdown)
That'll tell Swift that you really don't want to use the result of calling that function, and it doesn't need to warn you about it. That being said, the _
constant/variable is basically just a garbage can. You can assign to it all you want, but you can never read from it in a normal app
Andrea Miotto
iOS Development Techdegree Graduate 23,357 PointsAndrea Miotto
iOS Development Techdegree Graduate 23,357 PointsIsn't a waste of memory?
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsNope. Swift doesn't actually keep track of what's in the
_
variable. When you assign to it, you're just tossing whatever you're assigning to it into computational oblivion