[英]How to put specific values into an element of an array of arrays
我想知道如何將名稱值“ 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"],[],[],[],[],[]]
您需要訪問數組數組中的第一個數組,然后像這樣將那些元素插入其中:
array[0].append("123")
array[0].append("ok")
您可以通過以下方式實現相同的目標:
array[0] += ["123", "ok"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.