我想在swift中使用多个内部数组创建多维数组

时间:2016-06-10 05:37:12

标签: arrays swift

我想使用multidimensional array swift 中创建multiple inner arrays。我希望结构看起来像这样,但在创建时得到error。请指导我如何创建这种结构。

class ViewController: UIViewController
{
 var data2:[String] = []

    var LocationPickerData = ["Mozzarella","Gorgonzola","Provolone","Brie","Maytag Blue"]
    var LocationPickerData2 = ["Sharp Cheddar","Monterrey Jack","Stilton","Gouda","Goat Cheese", "Asiago"]
    var LocationPickerData3 = ["Goat Cheese", "Asiago"]

    var Title = ["twwwitle1","sdfsaf","Prsdfasovosdfasflone","sfsa","sdfsf Blue"]
    var Title2 = ["seeefdasf Cheddar","sdfsf Jack","fsaf","Gouda","fasf Cheese", "sdfsf"]
    var Title3 = ["ddddsdfs ff", "fasfsdffasf"]



    var Name = ["fsdfa","fasfsafsf","Provolone","Brie","Maytag Blue"]
    var Name2 = ["afsadff Cheddar","Monterrey Jack","Stilton","Gouda","Goat Cheese", "Asiago"]
    var Name3 = ["fffffff ffff", "jjjjjjj"]


var data2 = [
                    location[

                            location1[ LocationPickerData ],
                            location2[ LocationPickerData2],
                            location3[ LocationPickerData3]
                            ],
       titles[

                           title1[Title],
                           title2[Title2],
                           title3[Title3]
                        ],


                   names[

                          name1[Name],
                          name2[Name2],
                          name3[Name3]
                        ]
             ]
 }

1 个答案:

答案 0 :(得分:0)

声明你的多维数组:

var data2 = [ 
              [
                LocationPickerData
                LocationPickerData2,
                LocationPickerData3,
              ], 
              [
                Title
                Title2,
                Title3,
              ], 
              [
                Name
                Name2,
                Name3,
              ]
            ]

或者您可以声明字典:

var data2 = [ 
              "Locations": [
                LocationPickerData
                LocationPickerData2,
                LocationPickerData3,
              ], 
              "Titles": [
                Title
                Title2,
                Title3,
              ], 
              "Names": [
                Name
                Name2,
                Name3,
              ]
            ]