2012-06-05 25 views

回答

4

從CoreData的角度來看,你真的不創建新表,因爲數據庫表是唯一一個與核心數據模型相關聯的持久性存儲的可能的類型。

但是,您可以使用NSEntityDescription類以編程方式創建新的核心數據實體。在NSEntityDescription類的文檔,你會發現這一點:

Entity descriptions are editable until they are used by an object graph manager. This 
allows you to create or modify them dynamically. However, once a description is used 
(when the managed object model to which it belongs is associated with a persistent store 
coordinator), it must not (indeed cannot) be changed. This is enforced at runtime: any 
attempt to mutate a model or any of its sub-objects after the model is associated with a 
persistent store coordinator causes an exception to be thrown. If you need to modify a 
model that is in use, create a copy, modify the copy, and then discard the objects with 
the old model. 

我從來沒有試圖修改一個在運行時,所以我不知道到底有多好這個工作,當你有一個現有的SQLite持久存儲,如果在所有。但是可能值得與NSEntityDescription一起玩,看看它是否讓你接近你想要做的事情。

+0

感謝Tim,與許多iOS框架相比,coredata對我來說已經有點忙亂了。 – shebelaw

+0

嗯,把蒂姆...... –

+0

@shebelaw:這是相當複雜的開始,但如果你需要一個助推器,我會推薦大書呆子牧場書。他們用外行人的話說,他們也不會在布什附近毆打。 http://www.bignerdranch.com/books將亞馬遜書籍作爲二手拷貝書可能更便宜,但仍值得一看。 –

0

您通常使用Xcode的數據模型設計工具以圖形方式創建託管對象模型。 (如果你願意,你可以在運行時編程方式構建模型

Core Data programming Guide

+0

我不認爲這是可能的。你以前能做到這一點嗎? – shebelaw

+0

@Shanmugaraja G:您無法通過永久性存儲將程序拉入模型後以編程方式更改模型。但是,您可以更改商店未鎖定的型號。 –

0

但是,您可以:

  • 創建一個對象模型上下文(目前1以外你是在/使用)
  • 創建一個或多個實體
  • 爲該模型創建一個SEPARATE持久性存儲區
  • 保存實體等...
  • 關閉商店時,即可大功告成

不能動態更改模型,因爲它們是非常固定的,當他們拉進了運行時環境。

相關問題