Sending array of dictionaries with alamofire
// The problem was in append method. I have coded on PHP 5 years and forgoted that in Swift the indexes not automatically assigned like in PHP. So, my first bugged code was:
func getParameters() -> [[String: AnyObject]] {
var result = [[String: AnyObject]]()
for mmap in mmaps {
let material: [String: AnyObject] = [
"material_id": mmap.material.id,
"quantity": mmap.qty
]
result.append(material)
}
return result
}
// The answer is hard assign the keys as you need:
func getParameters() -> [String: [String: AnyObject]] {
var result = [String: [String: AnyObject]]()
let mmaps = self.mmaps.allObjects as [Mmap]
for i in 0..<mmaps.count {
let mmap = mmaps[i]
let material: [String: AnyObject] = [
"material_id": mmap.material.id,
"quantity": mmap.qty
]
result["\(i)"] = material
}
return result
}
Also in Swift:
- how to get appdelegate object in swift
- Decimal to Double conversion in Swift
- how to delete from list tvos swiftui coredata
- Failure Reason: SecurityUser Info: {DVTRadarComponentKey = 855031;RawLLDBErrorMessage = Security
- navigationview hide header swiftui
- swift create uinavigationcontroller programmatically
- swift file size from url
- how to get key for dictionary in swift
- how to add two right bar button item xcode
- ios swift convert int to string
- detect textfield change swiftui
- remove back button text nav bar swift
- how can i play video with url in a view in swift
- swift comments
- swift enum
- get item filter count swift
- double to string swift
- how to have diffrent size images in a stack view swift
- DispatchGroup example swift
- application tried to present a nil modal view controller on target
- how to get the path of selected PDF/doc from file manager in ios swift programmatically
- swift credit card validate
- how to low case string swift
- swift convert base64 string to data