Daibaku
Daibaku

Reputation: 12576

How to put specific values into an element of an array of arrays

I would like to know how to put name value "ok" and "123" into first array which is ["here"] I want other arrays to be empty.

    import Foundation
    import CoreLocation

    class Spot {

        let name: String
        let location: CLLocation

        init (lat: CLLocationDegrees, lng: CLLocationDegrees, name: String = "") {
            self.location = CLLocation(latitude: lat, longitude: lng)
            self.name = name
        }
    }//class

    extension Spot {

        static var list: [Spot] {

            return [

                Spot(lat: 35.124585, lng: 135.154821, name: "ok"),
                Spot(lat: 35.05406, lng: 136.215414, name: "123")
    ]
        }
    }

    var array = [["here"],[],[],[],[],[]]

Upvotes: 0

Views: 60

Answers (1)

Mo Abdul-Hameed
Mo Abdul-Hameed

Reputation: 6110

You need to access the first array in your array of arrays, and then insert those elements in it like this:

array[0].append("123")
array[0].append("ok")

You can achieve the same goal this way:

array[0] += ["123", "ok"]

Upvotes: 1

Related Questions