Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Swift 4中基于字典的键名中添加数组_Ios_Swift - Fatal编程技术网

Ios 如何在Swift 4中基于字典的键名中添加数组

Ios 如何在Swift 4中基于字典的键名中添加数组,ios,swift,Ios,Swift,我正试图在字典中添加数组 如何在Details1的ProductDetails中添加Details2,以便我可以在TableView上显示每行包含集合视图的内容 (((((self.completeDetailsArray[index] as! NSDictionary).mutableCopy()) as! NSMutableDictionary).value(forKey: "productDetails") as! NSArray).mutableCopy() as! NSMutable

我正试图在字典中添加数组

如何在Details1ProductDetails中添加Details2,以便我可以在TableView上显示每行包含集合视图的内容

(((((self.completeDetailsArray[index] as! NSDictionary).mutableCopy()) as! NSMutableDictionary).value(forKey: "productDetails") as! NSArray).mutableCopy() as! NSMutableArray).addObjects( from: productArray )
我尝试了这个不起作用的


这是正确的解决方案,或者我可以使用任何其他方法

您可以获得每个元素的详细信息1,如

var new = details1[0]
现在加上

new["productDetails"] = details2
并在主数组中添加新的

details[0] = new

使用

那你就可以这样做了

let details2:[ProductDetails] = [ProductDetails]()
details1.productDetails = details2

首先,不要做这样冗长复杂的陈述。把它分解成多个语句。@Moritz我添加了新代码,运行良好。所以我想问的是,这是最好的解决方案的其他方式吗?
let details2:[ProductDetails] = [ProductDetails]()
details1.productDetails = details2