尝试减少 Decimal 属性 给出: Type of expression is ambiguous without more context

Trying to reduce Decimal property gives: Type of expression is ambiguous without more context

我有一个名为 Transaction 的核心数据实体,其 属性 value 类型为 Decimal

我正在尝试减少交易数组,以求和 value 属性:

private var transactions = [Transaction]() {
    didSet {
        navigationItem.title = transactions.reduce(0.0) { [=11=].decimalNumberByAdding(.value) }
    }
}

但这会导致编译器错误:Type of expression is ambiguous without more context

如何通过对十进制求和来减少对象数组 属性?

发现尽管我的数据模型上的类型设置为 Decimal,但实际上类型是 NSDecimalNumber

所以它必须是:

let total = transactions.reduce(NSDecimalNumber(decimal: 0)) { [=10=].adding(.value ?? NSDecimalNumber(decimal: 0)) }
navigationItem.title = "$ \(total)"