2016-11-07 41 views

回答

4

創建一個抽象實體,您的兩個實體都從中繼承。

此外,如果您只顯示一個UITableView,請不要使用兩個NSFetchedResultsController,因爲如何將這兩個結合起來?你將如何訂購?

不喜歡這個:

例如,如果你想顯示Car S和Motorcycle S IN的的NSFetchedResultsController,創建一個類Vehicle並獲取Vehicle!而非。然後確保你設置Parent EntityVechicle在coredata模型編輯器都CarMotorcycle

enter image description here

編輯:這裏有一個答案提示同樣的事情(爲獲取一般請求,沒有特別NSFetchedResultControllerCore data: any way to fetch multiple entities?

+0

這也可以通過@Floyd對「核心數據:任何獲取多個實體的方式」提到的sqlite數據庫進行denormalise。 – kaushal

+0

Yepp。其實我有一個關於這個問題http://stackoverflow.com/questions/40338492/core-data-design-principles – netigger