I have a 2-dimensional 5x5 array in Swift. I am trying to have each array item to present a struct that has properties like cost and heuristics. for example, the grid[0][0] item should have cost and heuristics values.
Swift implementation:
struct Spot {
var cost: Int // cost
var heu: Int // heuristics
}
var grid = [[Int]]
In Javascript I used to do it as:
function Spot() {
this.cost = 0;
this.heu = 0;
}
//This is what I'm looking for something equivalent in Swift
grid[0][0] = new Spot();
Sorry if this seems very basic, but I'm a beginner in Swift.
Spotis (its name, and the names of its members don't really communicate much), you probably want an[[Int?]], withnils marking the empty spots, rather thanSpotinstances with 0 cost and 0 "heu"