Is there a way a computed property can return two separate values?

Tuples aren't really good for that. They're appropriate in cases when you want "dumb" containers of data that don't really correspond to any entity in the business domain.

For example, consider a type that's meant to be returned from a max() function, whose job is to find the index of the maximal value in an array, but also the maximal itself. You might right func max() -> (index: Int, element: Element). A tuple is appropriate, because you're just returning those two values, which don't form an easily nameable type (what would you call it? MaxReturnValue? Such a name would be useless).

But in your case, it sounds to me like you're probably missing an entity for your business domain. Perhaps a PurchaseReceipt or an ExpenseReport, or something along those lines. I suggest you make one of those, then add all the various properties that are relevant to it. Total cost, subtotal, tax amount, discount amounts, fees, splits, whatever.

/r/swift Thread Parent