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

[✨ FEAT] : CloudKit Manager 생성 #27

Closed
2 tasks done
GroundDev opened this issue Jul 17, 2022 · 4 comments · Fixed by #29
Closed
2 tasks done

[✨ FEAT] : CloudKit Manager 생성 #27

GroundDev opened this issue Jul 17, 2022 · 4 comments · Fixed by #29
Assignees
Labels
✨ FEAT 새로운 기능 구현 😀 Ground
Projects

Comments

@GroundDev
Copy link
Collaborator

GroundDev commented Jul 17, 2022

작업내용

  • CloudKit 관련한 작업들을 총괄하는 코드를 작성해보겠습니다.
  • 심층적인 개념 이해는 없이 무지성 클론코딩이 될 예정이므로, 아직 develop 브랜치에 merge시키지는 않겠습니다.

스크린샷

UI 작업은 없습니다.

Reference

레퍼런스는 그때그때 올릴게요.

@GroundDev GroundDev added ✨ FEAT 새로운 기능 구현 😀 Ground labels Jul 17, 2022
@GroundDev GroundDev self-assigned this Jul 17, 2022
@GroundDev GroundDev added this to To do in GiveCake via automation Jul 17, 2022
@GroundDev
Copy link
Collaborator Author

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

위에서 제시하는 순서대로 아래의 코드를 AppDelegate.swift에 추가하였습니다.

import UIKit
import CoreData
import CloudKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    lazy var persistentContainer: NSPersistentCloudKitContainer = {
    
        let container = NSPersistentCloudKitContainer(name: "GiveCake")
        container.loadPersistentStores(completionHandler: {
            (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()
...

@GroundDev
Copy link
Collaborator Author

https://www.raulferrergarcia.com/en/develop-a-todo-app-with-cloudkit/

다만 중간에 .perfrom()함수가 fetch()함수로 대체된다고 합니다.

    /// `CKQueryOperation` is the more configurable, `CKOperation`-based alternative to this method
    ///
    /// Queries can potentially return a large number of records, and the server will return those records in batches.  This API may return a `queryCursor` which can be used to continue the query via the `fetch(withCursor:)` function.
    ///
    /// The successful result of this function includes a dictionary mapping matched record IDs to the fetched record.
    ///
    /// If a record fails in post-processing (say, a network failure materializing a `CKAsset` record field), the record ID will map to a per-record error instead
    ///
    /// - Parameter zoneID: Declares which zone the query should target.  Nil indicates "perform query across all zones in the database"
    /// Queries invoked within a `sharedCloudDatabase` must specify a `zoneID`; cross-zone queries are not supported in a `sharedCloudDatabase`
    /// - Parameter desiredKeys: Declares which user-defined keys should be fetched and added to the resulting `CKRecord`s.  If `nil`, declares the entire record should be downloaded. If set to an empty array, declares that no user fields should be downloaded.
    /// - Parameter resultsLimit: If set, requests that the server limit the number of matched records sent in any one response.  The server may choose to set its own limit lower than this value.
    @available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
    public func fetch(withQuery query: CKQuery, inZoneWith zoneID: CKRecordZone.ID? = nil, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults, completionHandler: @escaping (Result<(matchResults: [(CKRecord.ID, Result<CKRecord, Error>)], queryCursor: CKQueryOperation.Cursor?), Error>) -> Void)

@SeonJeon
Copy link
Collaborator

https://www.raulferrergarcia.com/en/develop-a-todo-app-with-cloudkit/

다만 중간에 .perfrom()함수가 fetch()함수로 대체된다고 합니다.

    /// `CKQueryOperation` is the more configurable, `CKOperation`-based alternative to this method
    ///
    /// Queries can potentially return a large number of records, and the server will return those records in batches.  This API may return a `queryCursor` which can be used to continue the query via the `fetch(withCursor:)` function.
    ///
    /// The successful result of this function includes a dictionary mapping matched record IDs to the fetched record.
    ///
    /// If a record fails in post-processing (say, a network failure materializing a `CKAsset` record field), the record ID will map to a per-record error instead
    ///
    /// - Parameter zoneID: Declares which zone the query should target.  Nil indicates "perform query across all zones in the database"
    /// Queries invoked within a `sharedCloudDatabase` must specify a `zoneID`; cross-zone queries are not supported in a `sharedCloudDatabase`
    /// - Parameter desiredKeys: Declares which user-defined keys should be fetched and added to the resulting `CKRecord`s.  If `nil`, declares the entire record should be downloaded. If set to an empty array, declares that no user fields should be downloaded.
    /// - Parameter resultsLimit: If set, requests that the server limit the number of matched records sent in any one response.  The server may choose to set its own limit lower than this value.
    @available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
    public func fetch(withQuery query: CKQuery, inZoneWith zoneID: CKRecordZone.ID? = nil, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults, completionHandler: @escaping (Result<(matchResults: [(CKRecord.ID, Result<CKRecord, Error>)], queryCursor: CKQueryOperation.Cursor?), Error>) -> Void)

이 부분은 어떤 용도로 쓰이는건가요?? 올려주신 레퍼런스에 같은 코드가 기입되있지 않은거 같아 잘 이해가 안갑니다 ㅠ

@GroundDev
Copy link
Collaborator Author

GroundDev commented Jul 21, 2022

@SeonJeon
아 네! 위의 fetch 함수는 결국 쓰이지 않았습니다.
https://nsios.tistory.com/176
https://nsios.tistory.com/177
CloudKit manager는 위의 블로글을 참고해서 구현했어요.
CloudKit 이용하는 것 자체를 이해하지 못해서 아직 설명을 못했습니다
코드가 정리가 안되어 있다보니...
조만간 코드를 깔끔하게 정리하고 다시 이 부분 연재 시작해볼게요!

결론은 맞습니다 fetch함수는 쓰이지 않았어요.
참고로 위와 같은 함수가 어디있는지 알고 싶다면, command + 마우스 좌클릭을 하시면 Jump to Definition을 누르는게 나오게 되고
image
image
누르시면 아 이러이러한 구조로 쓰이는 녀석이구나 알 수 있습니다.
다만, 내부가 정확히 어떤 구조인지는 나타나있지 않아요. 이건 애플이 숨겨놨습니다. 함수가 정확히 어떤 내부를 갖고 있는 건지 궁금하시면 애플 UIKit 개발 부서로 입사하시면 됩니다!ㅎ 저희는 그저 이 함수가 어떤 용도인지, 어떻게 쓰면 되는지만 알 수 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ FEAT 새로운 기능 구현 😀 Ground
Projects
Development

Successfully merging a pull request may close this issue.

2 participants