Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list (po) the contents of a Swift Array?

Environment: Swift, Xcode 6

How do I get a list (po) of data items of a Swift array?

The following is Swift code for building a simple array:

kindArray += "Two" kindArray.append("Two")  var myStringArray: String[] myStringArray = ["One", "Two"] myStringArray.append("Three") myStringArray += "Four"  var firstItem = myStringArray[0] 

Here's the debug output:

(lldb) po firstItem "One"  (lldb) po kindArray Some  {   Some = 0x0ffb0000 {} } (lldb) po myStringArray size=1  {   [0] = {     core = {       _baseAddress = Builtin.RawPointer = 0x00000008       _countAndFlags = 34718       _owner = Some {         Some = (instance_type = Builtin.RawPointer = 0x80000003)       }     }   } } 

All I'm getting is 'Some' and 'size'.
I would like to show the contents.

like image 415
Frederick C. Lee Avatar asked Jun 15 '14 18:06

Frederick C. Lee


People also ask

How do you get an index of an array in Swift?

To find the index of a specific element in an Array in Swift, call firstIndex() method and pass the specific element for of parameter. Array. firstIndex(of: Element) returns the index of the first match of specified element in the array. If specified element is not present in the array, then this method returns nil .

How do you check if an array contains an item Swift?

It's easy to find out whether an array contains a specific value, because Swift has a contains() method that returns true or false depending on whether that item is found. For example: let array = ["Apples", "Peaches", "Plums"] if array.


1 Answers

Just do:

po print(myStringArray) 
like image 148
acastano Avatar answered Sep 28 '22 07:09

acastano