Reputation: 13
In DataModel. swift i have a class called DataModel with this struct :
struct pippo {
var x : Int
var y : Int
}
struct peppe {
var z : Int
var v : Int
}
struct franco {
var a : Int
var b : Int
}
Now i want to create an Array of Array of struct like this :
var array : [[DataModel.pippo],[DataModel.peppe],[DataModel.franco]] = [[],[],[]]
Is there a method ?
Upvotes: 0
Views: 94
Reputation: 369
struct pippo {
var x : Int
var y : Int
}
struct peppe {
var z : Int
var v : Int
}
struct franco {
var a : Int
var b : Int
}
struct Names {
var arrayPippo = [pippo]()
var arrayPeppe = [peppe]()
var arrayFranco = [franco]()
}
//After that create a array
class ViewController: UIViewController {
var names: [Names]()
override func viewDidLoad() {
super.viewDidLoad()
for name in names {
print(name.arrayFranco)
print(name.arrayPeppe)
print(name.arrayPippo)
for franco in name.arrayFranco {
print(franco.a)
}
}
}
}
Upvotes: 0
Reputation: 16341
Make another struct
struct Name {
var pippos = [Pippo]()
var peppes = [Peppe]()
var francos = [Franco]()
}
// Then array of names
var names = [Names]()
Upvotes: 2