Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

swift

lldb

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?

like image 335
ff10 Avatar asked Jul 05 '16 13:07

ff10


People also ask

What is some in Xcode?

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.

What is PO in Xcode?

"po" means something like "print object".

Where is console in Xcode?

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.


1 Answers

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.

like image 55
Alexander Avatar answered Sep 24 '22 11:09

Alexander