Pierre Prevalon Pierre Prevalon - 7 months ago 11
Swift Question

how to declare a dictionary inside two arrays

How can I declare a multi array outside its function so i can use it outside its function? I know how to do a regular array and a regular dictionary, but not both.

IhelpersCoordinates = [
[
"Latitude":IhelpersLatitude,
"Longitude": IhelpersLongitude,
"userId": IhelpersUid
]
]


The code above is in the viewDidLoad. I'm trying to use it in the user did update function. I know with a regular array i have to set the array outside of the function (example-
var IhelpersCordinates = []
). I'm trying to figure out how i would do the same with the array above.

Answer

Comment UPDATE

If you want to declare an dictionary inside an array inside an array try this code :

class YourClass {

    var IhelpersCoordinates : Array<Array<[String:Double]>> = [
            [
                    [
                            "Latitude": 53.02,
                            "Longitude": 19.04,
                            "userId": 123
                    ],

            ],
            [
                    [
                            "Latitude": 53.02,
                            "Longitude": 19.04,
                            "userId": 123
                    ],

            ],
    ]

    func exampleFunc(){
        print(IhelpersCoordinates[0][0]["Latitude"])
        print(IhelpersCoordinates.count)
    }
}

Hope it help you

Comments