我有一个名为“费用”的实体,链接到另一个称为“旅行”的实体。 如何访问与每项费用相关的旅程?核心数据:访问链接的实体属性
我与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