mirror of
https://github.com/tappollo/WWDC.git
synced 2026-01-12 22:45:32 +08:00
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
//
|
|
// CloudKitHelper.swift
|
|
// WWDC
|
|
//
|
|
// Created by Guilherme Rambo on 27/05/17.
|
|
// Copyright © 2017 Guilherme Rambo. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
import CloudKit
|
|
|
|
public final class CloudKitHelper {
|
|
|
|
public class func subscriptionExists(with name: String, in database: CKDatabase, completion: @escaping (Bool) -> Void) {
|
|
let fetchSubscriptionOperation = CKFetchSubscriptionsOperation(subscriptionIDs: [name])
|
|
|
|
fetchSubscriptionOperation.fetchSubscriptionCompletionBlock = { subscriptions, error in
|
|
if error is CKError {
|
|
DispatchQueue.main.async { completion(false) }
|
|
|
|
return
|
|
}
|
|
|
|
guard let subscriptions = subscriptions else {
|
|
NSLog("[LiveObserver] No subscriptions returned: nil value")
|
|
return
|
|
}
|
|
|
|
if !subscriptions.keys.contains(name) {
|
|
DispatchQueue.main.async { completion(false) }
|
|
}
|
|
}
|
|
|
|
database.add(fetchSubscriptionOperation)
|
|
}
|
|
|
|
}
|