Accessing same indexed element within 2D array swift -


is there syntactical way in swift access same indexed element within arrays within 2d array, akin accessing column in table, e.g.

let = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]  a[ 2 ] 

yields [ 7, 8, 9 ]. there way like

a[][ 2 ] 

yields [ 3, 6, 9 ]?

i know can do:

var b = [ int ]() c in {     b.append( c[ 2 ] ) } 

but wondering if there another, perhaps syntactical, way.

try this:

a.map { (elem) -> int in     return elem[2] } 

or short version (credits @ian):

a.map { $0[2] } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -