ドキュメントの状態:
...このメソッドは常にオブジェクトを返します。objectID で表される永続ストア内のデータは存在すると見なされます。存在しない場合、返されたオブジェクトは、プロパティにアクセスしたとき (つまり、障害が発生したとき) に例外をスローします。この動作の利点は、フォールトを作成して使用し、後で基礎となる行を作成するか、別のコンテキストで作成できることです。
また、Apple の「Core Recipes」サンプル アプリでは、メソッドの結果を使用して NSFetchRequest を設定し、リクエストの結果を使用して、その旨のコメントを付けています。
// first get the object into the context
Recipe *recipeFault = (Recipe *)[context objectWithID:objectID];
// this only creates a fault, which may NOT resolve to an object (for example, if the ID is for
// an objec that has been deleted already): create a fetch request to get the object for real
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity: [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:context]];
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(self == %@)", recipeFault];
[request setPredicate: predicate];
結果が直接使用される多くの例 (他のコードや Apple の「iClass」) を見てきましたobjectWithID。つまり、そのプロパティがアクセスされ、楽しく処理されます。
objectWithID 常に「おそらくこれが存在する」オブジェクトとして扱われるべきですか?
私はこれに出くわしたばかりで、その存在に反対していなかったので尋ねています.