ff10 ff10 - 1 year ago 76
Swift Question

What does the "Some" keyword in the Xcode console mean?

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
- Some: "Hello Jupiter"

What is the meaning of this keyword; why is it there?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download