2017-11-25 120 views
0

我想知道如何將名稱值「ok」和「123」放入第一個數組,這是[「here」]我希望其他數組爲空。如何將特定值放入數組數組中的一個元素

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"],[],[],[],[],[]] 

回答

1

您需要訪問的第一個數組的數組的數組中,然後將這些元素在這樣的:

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

可以達到同樣的目標是這樣的:

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

對於遲到的回覆感到抱歉。非常感謝你,我可以達到我想要的。再次感謝你!! – Daibaku

+0

不客氣,我很高興它幫助你 –

相關問題