I have a project with three entities: A One to Many Relationship form TransactionEntity to PurchaseEntity and SellEntity. I want to list the transactions of the two Entities inside one list and sort them by date or type of transaction(Purchase or sell). As an example: 01.01.2022 Purchase 02.01.2022 Purchase 03.01.2022 Sell 04.01.2022 Purchase.
I tried something like:
Struct Detail: View {
@StateObject var transaction: Transaction
var body: some View {
VStack {
ForEach(transaction.purchaseArray, transaction.sellArray) { transaction in
VStack {
Text(„\(transaction.purchaseArray.name ?? „“)„)
Text(„\(transaction.purchaseArray.value ?? „“)“)
Text(„\(transaction.purchaseArray.date ?? „“)“)
}
VStack {
Text(„\(transaction.sellArray.name ?? „“)„)
Text(„\(transaction.sellArray.value ?? „“)“)
Text(„\(transaction.sellArray.date ?? „“)“)
}
}
}
}
}
But that doesn’t work. But how can I display two entities in one list and sort them?