[英]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.