Saturday, 15 January 2011

swift - accessing values stored in multidimensional array -


I'm thinking ... there is a way to easily acces the value which is stored in a multi-dimensional array. I have given an example:

var arrayOfTwoArrays = [[2,3,4], [5,6,7]] arrayOfTwoArrays [0,2] // error saying: additional in call Logic should return the arrayOfTwoArrays [0,2] (if this has been done) value 4. It is not happening and I am getting an error Apple documentation model multi-dimensional array As a linear array, but I do not want extra work

An array of arrays is not the same as a multi-dimensional array (for example, internal Arrays can be of different sizes) So to get the value from the internal array, first bring it, and then subscript it: arrayOfTwoArrays [0] [2]

coincidence , If your intention was to get the last element of the first array, and the size of the arrays might be different and sometimes empty, you can write it like this:

  Let x = arrayOfTwoArrays.first? .last {// use x}  

which will account for the possibility of empty arrays. If you want to handle a specific prospect, you can handle else , or ?? .


No comments:

Post a Comment