2017-02-14 5 views
0

プロジェクトせずにレコードを保存」=私は私は私のコードビットそれはproj.titleように思えるCoreDataはcontextsave

let proj = Project(context: context!) 
let proj1 = Project(context: context!) 
//when i try to fetch for my proj nothing is there 

proj.title = "title" 
proj1.title = "title" 

//I find 2 record 

を変更

let proj = Project(context: context!) 
let proj1 = Project(context: context!) 
//at this point when i try to fetch for my proj nothing is there 

proj.title = "title" 
//I find 1 record 

を試してみてください今、私のNSManagedObject

let proj = Project(context: context!) 
//at this point when i try to fetch for my proj nothing is there 

proj.title = "title" 
//at this point I can fetch my project record 

ですタイトルはレコードを保存しています

I私のサブクラス内に.save()がありません

なぜですか?あなたはすぐにManagedObjectContext内の挿入後 managedObjectContext.save

答えて

1

オブジェクトが存在を呼び出すとき、私は私が唯一保存されているオブジェクトを考え

混乱しています。

.save()は、変更をMOCから親コンテキストまたは永続ストアにプッシュします。考え方は、スクラッチMOC内のオブジェクトを操作することができますが、「キャンセル」に応じてオブジェクトを投げ捨てることです。

同じ永続ストアを指している別のMOCを使用してフェッチを行うと、挿入に使用しているMOCに.save()がないと変更が表示されません。