我有一個名爲「費用」的實體,鏈接到另一個稱爲「旅行」的實體。 如何訪問與每項費用相關的旅程?核心數據:訪問鏈接的實體屬性
我與NSManagedObjects工作,所以作爲一個例子,我的方法這裏之一:
func fillCellWithExpense(cell: DayExpensesViewCell, expense: NSManagedObject) -> DayExpensesViewCell {
let amount = expense.value(forKey: AMOUNT) as! Double
cell.amountLabel?.text = String(format:"%.2f", amount)
let category = expense.value(forKey: CATEGORY) as! String
cell.categoryLabel?.text = category
switch category {
case "Transportation":
cell.line.backgroundColor = Colors.C1
case "Shopping":
cell.line.backgroundColor = Colors.C2
case "Food":
cell.line.backgroundColor = Colors.C3
case "Accomodation":
cell.line.backgroundColor = Colors.C4
case "Fun":
cell.line.backgroundColor = Colors.C5
case "Coffee":
cell.line.backgroundColor = Colors.C6
case "Groceries":
cell.line.backgroundColor = Colors.C7
default:
cell.line.backgroundColor = Colors.C8
}
return cell
}
如果我想訪問支出之旅的名字,我可以簡單地把NSManagedObject費用,然後訪問它的屬性?
let e = expense as! Expense
e.trip.value(forKey: "name")
你能提供你到目前爲止的代碼嗎? – carlos21