我正在尝试在我的词典中添加数组。
如何在 Details1 的 ProductDetails 中添加 Details2 所以我可以在TableView上显示每行包含集合视图。
(((((self.completeDetailsArray[index] as! NSDictionary).mutableCopy()) as! NSMutableDictionary).value(forKey: "productDetails") as! NSArray).mutableCopy() as! NSMutableArray).addObjects( from: productArray )
我尝试过这个无效的
let productArray : NSArray = responseResult.value(forKey: "details2") as! NSArray
let oldProductDict : NSMutableDictionary = (self.completeDetailsArray[index] as! NSDictionary).mutableCopy() as! NSMutableDictionary
let oldProductArray : NSArray = oldProductDict.value(forKey: "productDetails") as! NSArray
let completeProductArray = oldProductArray.addingObjects(from: productArray as! [Any])
oldProductDict.setValue(completeProductArray, forKey: "productDetails")
self.completeDetailsArray.replaceObject(at: index, with: oldProductDict)
let oldProductDict2 : NSDictionary = self.completeDetailsArray[index] as! NSDictionary
print("oldProductDict2",oldProductDict2)
这是正确的解决方案,或者我可以使用任何其他方式
答案 0 :(得分:1)
您可以获取详细信息的每个元素1,如
var new = details1[0]
现在添加
new["productDetails"] = details2
并将新数据添加到主数组中,如
details[0] = new
答案 1 :(得分:0)