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

[♻️ REFACTOR] : CloudKit Manager 정리 & 코드 설명 #45

Closed
3 of 4 tasks
GroundDev opened this issue Jul 22, 2022 · 3 comments
Closed
3 of 4 tasks

[♻️ REFACTOR] : CloudKit Manager 정리 & 코드 설명 #45

GroundDev opened this issue Jul 22, 2022 · 3 comments
Assignees
Labels
😀 Ground ♻️ REFACTOR 코드 정리를 할 때 (기능 변경 x)
Projects

Comments

@GroundDev
Copy link
Collaborator

GroundDev commented Jul 22, 2022

작업내용

  • 제가 CloudKit Manager 코드를 이해 못했습니다.
  • 그러면 안되는거잖아요 제가 쓴 코드인데
  • 그래서 코드 정리도 할 겸 제가 이해도 할 겸 팀원분들께 설명도 할 겸 이 이슈를 만들었습니다.
  • 관련된 브랜치도 만들어서 작업하겠습니다.

스크린샷

  • UI 작업은 없습니다.

Reference

  • 참고하는 레퍼런스는 그때그때 올릴게요.
@GroundDev GroundDev added ♻️ REFACTOR 코드 정리를 할 때 (기능 변경 x) 😀 Ground labels Jul 22, 2022
@GroundDev GroundDev self-assigned this Jul 22, 2022
@GroundDev GroundDev added this to To do in GiveCake via automation Jul 22, 2022
@GroundDev
Copy link
Collaborator Author

GroundDev commented Jul 22, 2022

import Foundation
import CloudKit

우선 시작은 import로 시작합니다. Foundation, CloudKit을 가져오겠습니다.
여기서 Foundation의 역할은 다음과 같습니다.

The Foundation framework provides a base layer of functionality for apps and frameworks, including data storage and persistence, text processing, date and time calculations, sorting and filtering, and networking.
https://developer.apple.com/documentation/foundation

정말 그야말로 기초적인 것들이 들어있는데요, 예를 들어 다음과 같은 녀석들도 들어있습니다.
image
네 이녀석을 쓰지 않을리가 없는거죠!
근데 궁금하네요. 우리 그냥 import SwiftUI만 하거나 import UIKit만 하는 경우도 있지 않았나요?
그건 사실

import Accessibility
import CoreGraphics
import DataDetection
import Dispatch
import Foundation // 어라 이미 들어있네요!
import UIKit.DocumentManager
import UIKit.NSAttributedString
import UIKit.NSDataAsset
...

위와 같이 SwiftUIUIKit에는 이 Foundation이 들어있습니다.
그러니 이제 이 이후로 import UIKit을 한 뒤에 import Foundation을 하는 친구가 있다면 빙그레 웃으며 그거 아니야 해주시면 됩니다.
굳이 Foundation 가져와있는데 또 가져올 필요가 없는거죠. 경험상 error가 발생하진 않는데, 굳이 또 쓸 필요는 없는겁니다.

@GroundDev
Copy link
Collaborator Author

GroundDev commented Jul 22, 2022

다음으로 CloudKit관련한 Manager를 만들 것이므로 import CloudKit을 하는건 너무나도 당연한 수순이겠죠!

The CloudKit framework provides interfaces for moving data between your app and your iCloud containers. You use CloudKit to store your app’s existing data in the cloud so that the user can access it on multiple devices. You can also store data in a public area where all users can access it.
https://developer.apple.com/documentation/cloudkit

보통은(모든 경우 그런건 아닙니다) 하나의 앱에는 하나의 container가 할당됩니다. 이 하나의 container에 이 앱을 쓰는 모든 이용자들이 접근하게 됩니다. 이러한 container에는 세 종류의 database가 존재합니다. public, private, shared 이렇게 세 가지죠. 위의 overview에도 나와 있듯이, 앱을 이용하는 모든 유저가 접근할 수 있으려면 public database에 data를 넣으면 됩니다. 현재 저희 팀의 CloudKit Manager는 이 public database 하나만 씁니다만, private, shared 또한 좀 더 공부해서 사용해보고 싶습니다.

이러한 CloudKit으로 만들어진 공간인 container에 있는 database들에 저장되는 형태는 바로 'record'의 형태로 저장됩니다.

A record is a dictionary of key-value pairs that represents the data you want to save.

iCloud로 올라가고 내려오는 데이터들은 바로 이 'record'와 밀접한 관련이 있습니다.

@GroundDev
Copy link
Collaborator Author

GroundDev commented Jul 25, 2022

https://storm-wholesaler-b52.notion.site/CoreData-CloudKit-Overview-ccb83fbad5ff4d04a143d794467dfdba
아이작이 CloudKit에다가 Core Data 연동해서 작업하면 매우 편하다고 팁을 주셨습니다.
원래는 애플 공식문서를 헤매면서 개념학습을 하고 있었는데, 이 내용이 저에겐 매우 충격적이네요
예를 들어

  • Core Data랑 연동하면은 작업이 훨씬 간단해지는 점이 있다는 점
  • Core Data 없이 CloudKit만을 이용하여 작업하면 객체 간의 관계를 정의하기가 복잡해진다는 점
  • 무엇보다도 private database과 public database간의 record 교환이 안된다는 점(이게 사실이라면 private, shared database는 사용 불가...)

등등 제 입장에선 충격적인 정보를 많이 얻었어요.
이에 아이작의 CloudKit 내용을 다시 살펴보면서 학습하겠습니다.
관련하여 공부한 내용 이슈로 정리할게요.
refactoring은 아이작이 주신 소스 공부한 이후 다시 진행하겠습니다.
이 이슈는 닫습니다.

GiveCake automation moved this from To do to Done Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
😀 Ground ♻️ REFACTOR 코드 정리를 할 때 (기능 변경 x)
Projects
Development

No branches or pull requests

1 participant