c++ - How to initialise a 3D array wich is of type myStruct in Swift? -
after heavy searching, found intuitive way of initialising 3d array in swift:
var firstarray = [int](count:4, repeatedvalue: 0) var secondarray = [[int]](count:4, repeatedvalue: firstarray) var thirdarray = [[[int]]](count:4, repeatedvalue: secondarray)
it works great. can access value of thirdarray:
thirdarray[a][b][c]
, in c++.
but if have struct like:
struct mystruct { var color: uicolor = uicolor.redcolor() var number: int = 0 var used: bool = true }
how use repeatedvalue?
var firstarray = [mystruct](count:4, repeatedvalue: ???)
simply use:
var newarray = [mystruct](count:4, repeatedvalue: mystruct())
the syntax creating instances of structs , classes same.
Comments
Post a Comment