Cocoaメモ

Appleプラットフォームでの開発メモ

NSPersistentContainer.loadPersistentStoresのcompletionHandlerはデフォルトで同期的に呼ばれる

NSPersistentContainer.loadPersistentStores(completionHandler:)のcompletionHandlerは、デフォルトではloadPersistentStoresを抜ける前に同期的に呼ばれます。

理由

NSPersistentContainer.persistentStoreDescriptions[0].shouldAddStoreAsynchronouslyがデフォルトでfalseになっているのが理由です。

NSPersistentStoreCoordinator.addPersistentStore(with:completionHandler:)も同様に、引数のstoreDescription.shouldAddStoreAsynchronouslyfalseの場合、completionHandlerが同期的に呼ばれます。

参考

stackoverflow.com