如何使用for
循環並添加我的四個字符串值的數組。請檢查下面的代碼:For-In循環Swift 3中的多個條件
let facilityID = FacilityID.map { "\($0)"}.joined(separator: ",")
let charges_per_km = ServiceChargesPerKilomiter.map { "\($0)"}.joined(separator: ",")
let charges_per_Minute = ServicChargesPerMinute.map { "\($0)"}.joined(separator: ",")
var request = URLRequest(url: URL(string: NetworkRequest.hostpath+"save_service_request.php")!)
request.httpMethod = "POST"
var data: [[String: Any]] = []
for i in 0..<facilityName.count {
let dataArray =
[
"facility_id": (facilityID),
"facility_name": facilityName[i],
"charges_per_km": (charges_per_km),
"charges_per_minute": (charges_per_Minute),
]
data.append(dataArray)
}
如何添加facilityID,Charges_per_km和charges_per_Minute我for
循環內?我將在for in
循環中添加facility_name。
任何人都可以幫助我嗎?
順便說一句,您可能希望採用標準的命名規則,特別是「駝峯」(以小寫字母開始的變量,將每個後續單詞的首字母大寫,例如'serviceChargesPerKilometer'或'chargesPerKm')。 – Rob