12

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?

ff10
  • 3,046
  • 1
  • 32
  • 55
  • 5
    Lookup the definition of `enum Optional`. It has two cases: `None` and ... `Some(Wrapped)`. – Martin R Jul 05 '16 at 13:18
  • Possible duplicate of [What is an optional value in Swift?](http://stackoverflow.com/questions/24003642/what-is-an-optional-value-in-swift) – JAL Jul 05 '16 at 14:42
  • @JAL I approach the issue from a different, more pragmatic angle. I think it's a valid question, however I also agree that the answers to the linked question implicitly answers my question. – ff10 Jul 08 '16 at 14:52

1 Answers1

13

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.

Alexander
  • 59,041
  • 12
  • 98
  • 151