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 trialDavid Keck
5,723 PointsQuestion on assignment syntax used
Why is the ? present in the code below?
person?.apartment = apartment
I know I should know this, but I can't recall.
1 Answer
David Keck
5,723 PointsFrom The Swift Programming Language:
βWhen working with optional values, you can write ? before operations like methods, properties, and subscripting. If the value before the ? is nil, everything after the ? is ignored and the value of the whole expression is nil. Otherwise, the optional value is unwrapped, and everything after the ? acts on the unwrapped value. In both cases, the value of the whole expression is an optional value.β
Excerpt From: Apple Inc. βThe Swift Programming Language (Swift 2.1 Prerelease).β Apple Inc., 2016-02-17T08:00:00Z. iBooks. This material may be protected by copyright.
Check out this book on the iBooks Store: https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=1002622538