swift - How to use a two dimensional array to store classes? -


i want create map in swift (two-dimensional) containing class on each field (groundtype, height, visible etc).

have found nothing how reallize this... examples have simple int or boolean content.

that can access like:

let currentfield = field[x,y].height() 

could help?

here example creating 5 x 3 multidimensional array hold classes of type field:

class field {     init (groundtype: string, height: double, visible: bool) {         self.groundtype = groundtype         self.height = height         self.visible = visible     }      var groundtype: string     var height: double     var visible: bool }  // two-dimensional array array of arrays.  use array constructor // twice create 5 3 multidimensional array var fields:[[field?]] = array(count: 5, repeatedvalue: array(count: 3, repeatedvalue: nil))  fields[4][2] = field(groundtype: "mountain", height: 4300.23, visible: true)  if let height = fields[4][2]?.height {     println(height) } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -