[iOS] CloudKit

Madeline๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ปยท2023๋…„ 10์›” 28์ผ
0

iOS study

๋ชฉ๋ก ๋ณด๊ธฐ
19/61
post-custom-banner

๐Ÿ˜–

CloudKit์ด ๋ญ์•ผ

  • ์•ฑ์˜ ๋ฐ์ดํ„ฐ๋ฅผ iCloud์— ์ €์žฅํ•˜๊ณ , ๋ชจ๋“  ๊ธฐ๊ธฐ์™€ ์›น์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ตœ์‹ ์ƒํƒœ๋กœ ์œ ์ง€
  • ํšจ์œจ์ ์ธ ๋™๊ธฐํ™”, ๊ฐ„๋‹จํ•œ ๋ชจ๋‹ˆํ„ฐ๋ง, ๊ด€๋ฆฌ ๊ธฐ๋Šฅ
  • ๋น„๊ณต๊ฐœ ๋ฐ์ดํ„ฐ โ†’ ์œ ์ €์˜ iCloud ๊ณ„์ •์— ์ €์žฅ๋˜๋ฏ€๋กœ, ์œ ์ € ์ธต์ด ๋Š˜์–ด๋‚˜๋„ ๋ฌด์ œํ•œ ํ™•์žฅ ๊ฐ€๋Šฅ
  • ๊ณต๊ฐœ ๋ฐ์ดํ„ฐ ์ €์žฅ ์ตœ๋Œ€ 1PB

์›๋ฆฌ

iCloud Container โ† iCloud Data

๊ธฐ๋ณธ ์›Œํฌํ”Œ๋กœ์šฐ

  1. ์•ฑ์„ ์‹œ์ž‘ํ•˜๊ณ  ์ฒ˜์Œ์— ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ฐ์— ํ•„์š”ํ•œ record๋ฅผ ๊ฐ€์ ธ์˜ด
  2. ์‚ฌ์šฉ์ž์˜ ์ž‘์—… or ๊ธฐ๋ณธ ์„ค์ •์— ๋”ฐ๋ผ ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•จ
  3. ๊ฐœ์ธ or ๊ณต์šฉ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ €์žฅ
  4. ์—ฌ๋Ÿฌ ์ €์žฅ ๋ฐ ๊ฐ€์ ธ์˜ค๊ธฐ ์ž‘์—…์„ ๋‹จ์ผ ์ž‘์—…์œผ๋กœ ์ผ๊ด„ ์ฒ˜๋ฆฌ
  5. ๊ด€์‹ฌ record๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ ํ‘ธ์‹œ ์•Œ๋ฆผ์„ ๋ฐ›์„ ๊ตฌ๋…์„ ๋งŒ๋“ฆ
  6. ์•ฑ์ด record์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ˆ˜์‹ ํ•˜๋ฉด, ๊ฐ์ฒด ๋ชจ๋ธ ๋ฐ ๋ณด๊ธฐ๋ฅผ ์—…๋ฐ์ดํŠธ
  7. ๋น„๋™๊ธฐ ์ž‘์—…์„ ์‹คํ–‰ํ•  ๋Œ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ

xcode์—์„œ iCloud๋ฅผ ์„ค์ •ํ•ด๋ณด์ž

project >> sigining & capabilities >> iCloud
์„ ์„ค์ •ํ•˜๋ฉด ์•„๋ž˜ ํ•˜์œ„ ํ•ญ๋ชฉ๋“ค์„ ์ฒดํฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜์–ด์žˆ๋‹ค.
์ด ํ•ญ๋ชฉ๋“ค์ด ๋ญ๋ƒ๋ฉด,

  • Key-value storage
    • ์œ ์ €๋””ํดํŠธ์ฒ˜๋Ÿผ ์‚ฌ์šฉ์ž๋‹น maximum 1MB size ๊ณต๊ฐ„ ์‚ฌ์šฉ๊ฐ€๋Šฅ
    • Key: 1024๊ฐœ
    • Value: 1MB
    • ๊ฐ Key์— ๋Œ€ํ•œ 1KB ๋ฐ์ดํ„ฐ ์ €์žฅํ•˜๋Š” ๊ฒฝ์šฐ, 1000๊ฐœ์˜ key-value ์Œ์„ ์‚ฌ์šฉ
  • iCloud Documents
    • ์•ฑ์˜ ๋ฌธ์„œ๋ฅผ ๋ชจ๋“  ์‚ฌ์šฉ์ž์˜ ๊ธฐ๊ธฐ์—์„œ ์‚ฌ์šฉ
  • CloudKit
    • ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ record, ๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐฉ๋ฒ• ์ œ๊ณต
    • Record Type
    • key-value ๋”•์…”๋„ˆ๋ฆฌ ๊ตฌ์กฐ, ๊ฐ ํ‚ค == record์˜ ํ•œ ํ•„๋“œ
    • ํ•„๋“œ: String, number, date, location, reference, asset
    • iCloud๊ฐ„ ๋ฐ์ดํ„ฐ ์ด๋™ ๋ฐ ์•ฑ ์‚ฌ์šฉ์ž๊ฐ„ ๋ฐ์ดํ„ฐ ๊ณต์œ ์ด๋ฏ€๋กœ, ์•ฑ์˜ ๋ชจ๋ธ ๊ฐ์ฒด ๋Œ€์ฒดํ•˜๋ฉด ์•ˆ๋˜๊ณ , ๊ฐ์ฒด๋ฅผ ๋กœ์ปฌ๋กœ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•ด์„œ๋„ ์•ˆ๋จ
    • ๋น„๋™๊ธฐ
    • ๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด completion handler ์ œ๊ณตํ•ด์•ผ ํ•จ
    • ์ด๊ฑฐ ์ฒดํฌํ•˜๋ฉด ํ‘ธ์‹œ ์•Œ๋ฆผ์„ ๋ฐ›์„ ๊ตฌ๋…์„ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์—, Push Notifications๋„ ๊ฐ™์ด ์ถ”๊ฐ€๋จ

CloudKitTrial์„ ๋งŒ๋“ค์–ด๋ณด์ž

๐Ÿค“ Reference
[Swift] iCloud ์—ฐ๋™ CloudKit ์‚ฌ์šฉํ•˜๊ธฐ(1/2) - ์ถ”๊ฐ€ ๋ฐ ์„ค์ •

  • โ€œ+โ€ โ†’ container ์ถ”๊ฐ€

  • Apple Developer ์‚ฌ์ดํŠธ์— App ID ๋“ฑ๋ก

https://developer.apple.com/account/resources/certificates/list

  • Identifiers โ†’ Register a new identifier

  • App ID ๋“ฑ๋กํ•˜๋Š” ํ™”๋ฉด์—์„œ ์•„๋ž˜์— iCloud ์ฒดํฌ

  • Bundle id์“ฐ๋ฉด ๋

  • iCloud database๋ฅผ ์ฝ˜์†”์—์„œ ํ™•์ธ

https://icloud.developer.apple.com/dashboard/home/teams/MTUYFM4K8P

์ค‘๊ฐ„์— ์™œ ๊ณ„์† ์•ˆ๋˜์—ˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ, xcode์—์„œ container๋ฅผ 2๊ฐœ ๋งŒ๋“œ๋‹ˆ๊นŒ ์ด ํ™”๋ฉด์ด ๋œธ..

๐Ÿคจ ์•„๋ฌดํŠผ ์ด ํ™”๋ฉด์ด ๋–ด์œผ๋‹ˆ๊นŒ,

  • Schema ํƒญ โ†’ Record Types โ†’ โ€œ+โ€๋ฒ„ํŠผ์œผ๋กœ ์‚ฌ์šฉํ•  ํƒ€์ž… ์ •์˜

  • ๋ธ”๋กœ๊ทธ ๋”ฐ๋ผ์„œ โ€œBookโ€ record type ๋งŒ๋“ค์–ด๋ณด๊ณ 

  • Record Fields์— name(String), price(Int64) ์ถ”๊ฐ€ โ†’ Save Changes

indexes ์„ค์ •

  • ํšจ์œจ์ ์œผ๋กœ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ• ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด์„œ!!

  • name์„ ์ •๋ ฌํ•ด์„œ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ๋‹ค โ†’ sortable ์ถ”๊ฐ€
  • name์„ ์ฟผ๋ฆฌ๋กœ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์‹ถ๋‹ค โ†’ queryable ์ถ”๊ฐ€

  • ๋”๋ฏธ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค์ž. Records โ†’ โ€œ+โ€๋ฒ„ํŠผ โ†’ create new record

  • Type: Book์œผ๋กœ ํ•ด์„œ Field์— ๋ฐ์ดํ„ฐ๋ฅผ ์ฑ„์›Œ์ค๋‹ˆ๋‹น

  • ์ €์žฅ!

  • ์ €์žฅํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์•„๋ณด์ž. Records โ†’ ์•„๋ž˜ ํƒญ๋ฐ”์— Record type๋ฅผ Book์œผ๋กœ ์„ค์ •ํ•˜๊ณ  โ€œQuery Recordsโ€ํ•˜๋ฉด ๊ฒ€์ƒ‰์ด ๋œ๋‹ค

  • ์ด์ œ Xcode์—์„œ Book์ด๋ผ๋Š” Record ํƒ€์ž…์„ ๋ถˆ๋Ÿฌ์˜ค๊ณ , ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์–ด์ค„ ์ˆ˜ ์žˆ๊ฒŒ ํ•˜์ž.

์•Œ์•„์•ผ ํ•˜๋Š” ํƒ€์ž…

  • CKRecord
  • CKContainer
  • CKQuery
  • CKQueryOperation

Private Database

  • reading from and writing to a Private Database for a user in your own container on CloudKit servers

https://github.com/apple/sample-cloudkit-privatedb

(์•ˆ์“ธ๋“ฏ)=====================

  • CloudKit: Sharing

ํ•œ ๊ณ„์ •์—์„œ ๋‹ค๋ฅธ ๊ณ„์ •์œผ๋กœ ๊ณต์œ ํ•˜๋Š”๊ฑฐ๋‹ˆ๊น ์šฐ๋ฆฌ๊ฑฐ ์•„๋‹ˆ๊ฒ ์ง€?

https://github.com/apple/sample-cloudkit-sharing

  • CKSyncEngine?

https://github.com/apple/sample-cloudkit-sync-engine

profile
๐ŸŽ Apple Developer Academy@POSTECH 2๊ธฐ, ๐Ÿ€ SeSAC iOS 4๊ธฐ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€