Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreDataのCloud周りを調べる #12

Closed
Moriya-Taichi opened this issue Nov 19, 2020 · 4 comments
Closed

CoreDataのCloud周りを調べる #12

Moriya-Taichi opened this issue Nov 19, 2020 · 4 comments

Comments

@Moriya-Taichi
Copy link
Owner

CoreDataと言えばiCloudへのバックアップでしょ
と思うのでこれも調査したい

@Moriya-Taichi
Copy link
Owner Author

https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit#3191035

CoreDataと合わせて使うにはモデルに制約がかかるらしい

  • Uniqueは使えない
  • Undefinedは使えない
  • Relationは全てoptionalでなければならない
  • 逆のRelationをつけるのを推奨
  • 削除時のdenyは使えない
  • 別のConfigurationのエンティティとRelationを持ってはならない

@Moriya-Taichi
Copy link
Owner Author

https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit

大まかな手順

@Moriya-Taichi
Copy link
Owner Author

同期の仕組み

  • CloudKitを利用しての同期に際して、コードの追加は必要ない
  • 通常のCoreDataと同じでNSManagedObjectの変更があると勝手にiCloudに流してくれる
  • iCloudからは通知で変更を送っていて、クライアント側では自動的に変換して保存してくれる
  • 通常は1分以内に変更の通知が来るのが期待される

@Moriya-Taichi
Copy link
Owner Author

セットアップ

  • NSPersistentContainer -> NSPersistentCloudKitContainer
  • Cloudで使いたいエンティティのConfigurationに追加してCloudとLocalで ミラーリングするように設定
    初期化周りはドキュメントのコピペで余裕そう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant