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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
如何在swift中获取字典中值的总和?_Swift - Fatal编程技术网

如何在swift中获取字典中值的总和?

如何在swift中获取字典中值的总和?,swift,Swift,字典:[字符串:双精度]=[:] 字典=[07/03/21:331,08/03/21:854,09/03/21:-80] 如何添加字典的值? sum=331+854+-80变量字典:[字符串:双精度]=[:] 字典=[07/03/21:331,08/03/21:854,09/03/21:-80] 设sum=dictionary.compactMap{$0.value}.reduce0+ 打印总数 为什么不干脆让sum=dictionary.reduce0{$0+$1.value}?顺便说一句,S

字典:[字符串:双精度]=[:]

字典=[07/03/21:331,08/03/21:854,09/03/21:-80]

如何添加字典的值? sum=331+854+-80变量字典:[字符串:双精度]=[:] 字典=[07/03/21:331,08/03/21:854,09/03/21:-80] 设sum=dictionary.compactMap{$0.value}.reduce0+ 打印总数 为什么不干脆让sum=dictionary.reduce0{$0+$1.value}?顺便说一句,Swift 5.2或更高版本可以使用keyPath compactMap\.valuelet sum=dictionary.reduce0{$0+$1.value}