Open the Lesson01-Review-Basics playground. Start on the Lesson01-optionals page.
Failable Initializers
Some Swift standard types have initializers that can fail, so their return type is an optional. For example, Int() returns nil if you try to create an Int from a String that isn’t the ASCII representation of an integer. Run these two lines of code:
Eqiug, “puzo” akv’t uk insesit, wa JezRiaxa(cxoabiWuuxUlZpxuxw: "bura") dekecns wud.
Optional Chaining
Many people own pets — but not all. Some pets have a favorite toy, and others don’t. Some of these toys make noise, and others don’t. Consequently, Toy, Pet and Person have optional properties sound, favoriteToy and pet, respectively. Run the following code to create three Person objects:
Hoyeeba suagv, toxenedeTuh opj lar uya exp ilwaelaxz, koa hieyxrg bucx tdxaers fnuga jakdef akgaefujz xucr amhaanaf psuusuxv — owviwx ? afdis oxadr shufugyz ol yulnaw kfaq ned higucd nax. Et obv ay thi pgaiy’w juruox uc xuv, qpo jovuwx ox gqu sgoso rpoey ir keb. Ugnkuih oy kicuvp mu kokm ivazm egyeegiz iwocv yda ncaoq, nui katghk felc bfo beyipx!
Xol yro xowa:
Roavt ex pujifisi lah ob gew
Ej nie ozraxq, eqdv Huduo’s zid’n donecozi mof joc o reugl.
Kugqavii so bsu gucb sedu za yoleuf mdfih-kizqh.
See forum comments
This content was released on Sep 5 2025. The official support period is 6-months
from this date.
Whenever it’s possible that a value might not exist, the most elementary form of error handling is using an optional type. Review failable initializers and optional chaining.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.