Meaning of optionals? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Meaning of optionals?

What is meant by "wrapping" and "unwrapping" in the context of describing how optionals work? Does it imply some kind of surrounding a variable or value with something?!

18th Nov 2016, 6:47 PM
Stephen Learmonth
Stephen Learmonth - avatar
4 Answers
+ 1
Swift, for safety reasons, requires all variables and constants to always hold a value. This prevents that scenario where the value of a variable can be unknown. To solve this problem, Swift created the typeOptional that can either hold no value (None) or hold some value (Some).
1st Dec 2016, 11:27 AM
Felipe Cruz
Felipe Cruz - avatar
0
Thanks for your reply but it still doesn't explain why the term "wrapping" is used?
3rd Dec 2016, 12:23 PM
Stephen Learmonth
Stephen Learmonth - avatar
0
When you wrap a variable means that you dont have to know what is inside the variable. Manage the variable as it holds either none or some value.
3rd Dec 2016, 12:42 PM
Felipe Cruz
Felipe Cruz - avatar
- 1
menage?
3rd Dec 2016, 1:20 PM
Stephen Learmonth
Stephen Learmonth - avatar