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 trialMatt Conway
1,572 PointsVariable
Cant seem to get this right ...
Challenge Task 1 of 1
Declare a variable named someValue of type optional Int and assign nil.
Note: You will have to explicitly declare the type as an optional Int otherwise the compiler cannot infer it.
let variable = someValue: Int == nil
1 Answer
jcorum
71,830 Pointsvar someValue: Int? = nil
You declare a variable using the var keyword. You give it a name: someValue. Then, following the : you indicate the type, which here is Int?, or an optional Int. Then you assign nil.
jenko
8,562 Pointsjenko
8,562 PointsIt's easy to forget to delcare the type. This had me held up for quiet a bit.
Time to head back and refresh my knowladge on basics I think!