Ios 如何在Swift 4中基于字典的键名中添加数组
我正试图在字典中添加数组 如何在Details1的ProductDetails中添加Details2,以便我可以在TableView上显示每行包含集合视图的内容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
(((((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