Printing the description of an object yields lldb to use the keyword "Some" in front of the object's description (here I po an optional string):
(lldb) po someString
Optional<String>
- Some: "Hello Jupiter"
What is the meaning of this keyword; why is it there?
Opaque Types The some keyword was introduced in Swift 5.1 and is used to define an Opaque Type. An opaque type is a way to return a type without needing to provide details on the concrete type itself.
"po" means something like "print object".
Here is small tip for Xcode developers. To show/hide the Console click the icon Show/Hide the console in the lower right corner. It's the last icon on the lower right side of the panel.
Optional
is an enum
with two cases, none
, and some(wrapped)
:
enum Optional<Wrapped> {
case some(Wrapped)
case none
}
As you can see, the Optional
either has a value of Some
, with an associated value (the value the Optional
wraps), or None
. Optional.None
is actually the meaning of nil
.
In this case, the debugger is telling you that someString
is an Optional<String>
(a.k.a. String?
), which has a value of Optional.Some("Hello Jupiter")
. It's not Optional.None
, thus it's not nil
.
Prior to Swift 3, these cases were capitalized, Some
and None
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With