Add PromiseKit dependency
- Added PromiseKit dependency
This commit is contained in:
79
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+AnyPromise.h
vendored
Normal file
79
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+AnyPromise.h
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
#import <CloudKit/CKContainer.h>
|
||||
#import <PromiseKit/AnyPromise.h>
|
||||
|
||||
/**
|
||||
To import the `CKContainer` category:
|
||||
|
||||
use_frameworks!
|
||||
pod "PromiseKit/CloudKit"
|
||||
|
||||
And then in your sources:
|
||||
|
||||
@import PromiseKit;
|
||||
*/
|
||||
@interface CKContainer (PromiseKit)
|
||||
|
||||
/**
|
||||
Reports whether the current user’s iCloud account can be accessed.
|
||||
|
||||
@return A promise that thens the `CKAccountStatus` of this container.
|
||||
*/
|
||||
- (AnyPromise *)accountStatus NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
Requests the specified permission from the user asynchronously.
|
||||
|
||||
@param applicationPermission The requested permission.
|
||||
|
||||
@return A promise that thens the `CKApplicationPermissionStatus` for the
|
||||
requested permission.
|
||||
*/
|
||||
- (AnyPromise *)requestApplicationPermission:(CKApplicationPermissions)applicationPermission NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
Checks the status of the specified permission asynchronously.
|
||||
|
||||
@param applicationPermission The permission whose status you want to
|
||||
check.
|
||||
|
||||
@return A promise that thens the `CKApplicationPermissionStatus` for
|
||||
the requested permission.
|
||||
*/
|
||||
- (AnyPromise *)statusForApplicationPermission:(CKApplicationPermissions)applicationPermission NS_REFINED_FOR_SWIFT;
|
||||
|
||||
#if !(TARGET_OS_TV && (TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR))
|
||||
/**
|
||||
|
||||
Retrieves information about all discoverable users that are known to the
|
||||
current user.
|
||||
|
||||
@return A promise that thens the array of `CKDiscoveredUserInfo` objects.
|
||||
*/
|
||||
#if TARGET_OS_WATCH
|
||||
- (AnyPromise *)discoverAllIdentities NS_REFINED_FOR_SWIFT;
|
||||
#else
|
||||
- (AnyPromise *)discoverAllContactUserInfos NS_REFINED_FOR_SWIFT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
Retrieves information about a single user based on that user’s email
|
||||
address or record ID.
|
||||
|
||||
@param emailStringOrRecordID Either the email string or the `CKRecordID`
|
||||
for the user record.
|
||||
|
||||
@return A promise that thens the `CKDiscoveredUserInfo` for the
|
||||
requested user record.
|
||||
*/
|
||||
- (AnyPromise *)discoverUserInfo:(id)emailStringOrRecordID NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/**
|
||||
Returns the user record associated with the current user.
|
||||
|
||||
@return A promise that thens the `CKRecord` for the current user or `nil`
|
||||
if there is no current user.
|
||||
*/
|
||||
- (AnyPromise *)fetchUserRecordID NS_REFINED_FOR_SWIFT;
|
||||
|
||||
@end
|
||||
71
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+AnyPromise.m
vendored
Normal file
71
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+AnyPromise.m
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
#import <CloudKit/CKRecordID.h>
|
||||
#import "CKContainer+AnyPromise.h"
|
||||
|
||||
@implementation CKContainer (PromiseKit)
|
||||
|
||||
- (AnyPromise *)accountStatus {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error) {
|
||||
resolve(error ?: @(accountStatus));
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (AnyPromise *)requestApplicationPermission:(CKApplicationPermissions)permissions {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self requestApplicationPermission:permissions completionHandler:^(CKApplicationPermissionStatus status, NSError *error) {
|
||||
resolve(error ?: @(status));
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (AnyPromise *)statusForApplicationPermission:(CKApplicationPermissions)applicationPermission {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self statusForApplicationPermission:applicationPermission completionHandler:^(CKApplicationPermissionStatus status, NSError *error) {
|
||||
resolve(error ?: @(status));
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
#if !(TARGET_OS_TV && (TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR))
|
||||
#if TARGET_OS_WATCH
|
||||
- (AnyPromise *)discoverAllIdentities {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self discoverAllIdentitiesWithCompletionHandler:^(NSArray *userInfos, NSError *error) {
|
||||
resolve(error ?: userInfos);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
#else
|
||||
- (AnyPromise *)discoverAllContactUserInfos {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self discoverAllIdentitiesWithCompletionHandler:^(NSArray *userInfos, NSError *error) {
|
||||
resolve(error ?: userInfos);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
- (AnyPromise *)discoverUserInfo:(id)input {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
void (^adapter)(id, id) = ^(id value, id error){
|
||||
resolve(error ?: error);
|
||||
};
|
||||
if ([input isKindOfClass:[CKRecordID class]]) {
|
||||
[self discoverUserIdentityWithUserRecordID:input completionHandler:adapter];
|
||||
} else {
|
||||
[self discoverUserIdentityWithEmailAddress:input completionHandler:adapter];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (AnyPromise *)fetchUserRecordID {
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
||||
[self fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
|
||||
resolve(error ?: recordID);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
79
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+Promise.swift
vendored
Normal file
79
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKContainer+Promise.swift
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
import CloudKit
|
||||
#if !PMKCocoaPods
|
||||
import PromiseKit
|
||||
#endif
|
||||
|
||||
#if swift(>=4.2)
|
||||
#else
|
||||
public extension CKRecord {
|
||||
typealias ID = CKRecordID
|
||||
}
|
||||
public typealias CKContainer_Application_Permissions = CKApplicationPermissions
|
||||
public typealias CKContainer_Application_PermissionStatus = CKApplicationPermissionStatus
|
||||
#endif
|
||||
|
||||
/**
|
||||
To import the `CKContainer` category:
|
||||
|
||||
use_frameworks!
|
||||
pod "PromiseKit/CloudKit"
|
||||
|
||||
And then in your sources:
|
||||
|
||||
@import PromiseKit;
|
||||
*/
|
||||
extension CKContainer {
|
||||
/// Reports whether the current user’s iCloud account can be accessed.
|
||||
public func accountStatus() -> Promise<CKAccountStatus> {
|
||||
return Promise { accountStatus(completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Requests the specified permission from the user asynchronously.
|
||||
public func requestApplicationPermission(_ applicationPermissions: CKContainer_Application_Permissions) -> Promise<CKContainer_Application_PermissionStatus> {
|
||||
return Promise { requestApplicationPermission(applicationPermissions, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Checks the status of the specified permission asynchronously.
|
||||
public func status(forApplicationPermission applicationPermissions: CKContainer_Application_Permissions) -> Promise<CKContainer_Application_PermissionStatus> {
|
||||
return Promise { status(forApplicationPermission: applicationPermissions, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
/// Retrieves information about all discoverable users that are known to the current user.
|
||||
@available(*, deprecated)
|
||||
public func discoverAllContactUserInfos() -> Promise<[CKUserIdentity]> {
|
||||
return Promise { discoverAllIdentities(completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
public func discoverAllIdentities() -> Promise<[CKUserIdentity]> {
|
||||
return Promise { discoverAllIdentities(completionHandler: $0.resolve) }
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Retrieves information about a single user based on that user’s email address.
|
||||
@available(*, deprecated)
|
||||
public func discoverUserInfo(withEmailAddress email: String) -> Promise<CKUserIdentity> {
|
||||
return Promise { discoverUserIdentity(withEmailAddress: email, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Retrieves information about a single user based on that user’s email address.
|
||||
public func discoverUserIdentity(withEmailAddress email: String) -> Promise<CKUserIdentity> {
|
||||
return Promise { discoverUserIdentity(withEmailAddress: email, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Retrieves information about a single user based on the ID of the corresponding user record.
|
||||
@available(*, deprecated)
|
||||
public func discoverUserInfo(withUserRecordID recordID: CKRecord.ID) -> Promise<CKUserIdentity> {
|
||||
return Promise { discoverUserIdentity(withUserRecordID: recordID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Retrieves information about a single user based on the ID of the corresponding user record.
|
||||
public func discoverUserIdentity(withUserRecordID recordID: CKRecord.ID) -> Promise<CKUserIdentity> {
|
||||
return Promise { discoverUserIdentity(withUserRecordID: recordID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Returns the user record ID associated with the current user.
|
||||
public func fetchUserRecordID() -> Promise<CKRecord.ID> {
|
||||
return Promise { fetchUserRecordID(completionHandler: $0.resolve) }
|
||||
}
|
||||
}
|
||||
46
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+AnyPromise.h
vendored
Normal file
46
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+AnyPromise.h
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
#import <CloudKit/CKDatabase.h>
|
||||
#import <PromiseKit/AnyPromise.h>
|
||||
|
||||
/**
|
||||
To import the `CKDatabase` category:
|
||||
|
||||
use_frameworks!
|
||||
pod "PromiseKit/CloudKit"
|
||||
|
||||
And then in your sources:
|
||||
|
||||
@import PromiseKit;
|
||||
*/
|
||||
@interface CKDatabase (PromiseKit)
|
||||
|
||||
/// Fetches one record asynchronously from the current database.
|
||||
- (AnyPromise *)fetchRecordWithID:(CKRecordID *)recordID NS_REFINED_FOR_SWIFT;
|
||||
/// Saves one record zone asynchronously to the current database.
|
||||
- (AnyPromise *)saveRecord:(CKRecord *)record NS_REFINED_FOR_SWIFT;
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
- (AnyPromise *)deleteRecordWithID:(CKRecordID *)recordID NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/// Searches the specified zone asynchronously for records that match the query parameters.
|
||||
- (AnyPromise *)performQuery:(CKQuery *)query inZoneWithID:(CKRecordZoneID *)zoneID NS_REFINED_FOR_SWIFT;
|
||||
|
||||
/// Fetches all record zones asynchronously from the current database.
|
||||
- (AnyPromise *)fetchAllRecordZones NS_REFINED_FOR_SWIFT;
|
||||
/// Fetches one record asynchronously from the current database.
|
||||
- (AnyPromise *)fetchRecordZoneWithID:(CKRecordZoneID *)zoneID NS_REFINED_FOR_SWIFT;
|
||||
/// Saves one record zone asynchronously to the current database.
|
||||
- (AnyPromise *)saveRecordZone:(CKRecordZone *)zone NS_REFINED_FOR_SWIFT;
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
- (AnyPromise *)deleteRecordZoneWithID:(CKRecordZoneID *)zoneID NS_REFINED_FOR_SWIFT;
|
||||
|
||||
#if !(TARGET_OS_WATCH && (TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR))
|
||||
/// Fetches one record asynchronously from the current database.
|
||||
- (AnyPromise *)fetchSubscriptionWithID:(NSString *)subscriptionID NS_REFINED_FOR_SWIFT;
|
||||
/// Fetches all subscription objects asynchronously from the current database.
|
||||
- (AnyPromise *)fetchAllSubscriptions NS_REFINED_FOR_SWIFT;
|
||||
/// Saves one subscription object asynchronously to the current database.
|
||||
- (AnyPromise *)saveSubscription:(CKSubscription *)subscription NS_REFINED_FOR_SWIFT;
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
- (AnyPromise *)deleteSubscriptionWithID:(NSString *)subscriptionID NS_REFINED_FOR_SWIFT;
|
||||
#endif
|
||||
|
||||
@end
|
||||
41
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+AnyPromise.m
vendored
Normal file
41
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+AnyPromise.m
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
#import "CKDatabase+AnyPromise.h"
|
||||
|
||||
@implementation CKDatabase (PromiseKit)
|
||||
|
||||
#define mkmethod1(method) \
|
||||
- (AnyPromise *)method { \
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) { \
|
||||
[self method ## WithCompletionHandler:^(id a, id b){ \
|
||||
resolve(b ?: a); \
|
||||
}]; \
|
||||
}]; \
|
||||
}
|
||||
|
||||
#define mkmethod2(method) \
|
||||
- (AnyPromise *)method { \
|
||||
return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) { \
|
||||
[self method completionHandler:^(id a, id b){ \
|
||||
resolve(b ?: a); \
|
||||
}]; \
|
||||
}]; \
|
||||
}
|
||||
|
||||
mkmethod2(fetchRecordWithID:(CKRecordID *)recordID);
|
||||
mkmethod2(saveRecord:(CKRecord *)record);
|
||||
mkmethod2(deleteRecordWithID:(CKRecordID *)recordID);
|
||||
|
||||
mkmethod2(performQuery:(CKQuery *)query inZoneWithID:(CKRecordZoneID *)zoneID);
|
||||
|
||||
mkmethod1(fetchAllRecordZones);
|
||||
mkmethod2(fetchRecordZoneWithID:(CKRecordZoneID *)zoneID);
|
||||
mkmethod2(saveRecordZone:(CKRecordZone *)zone);
|
||||
mkmethod2(deleteRecordZoneWithID:(CKRecordZoneID *)zoneID);
|
||||
|
||||
#if !(TARGET_OS_WATCH && (TARGET_OS_EMBEDDED || TARGET_OS_SIMULATOR))
|
||||
mkmethod2(fetchSubscriptionWithID:(NSString *)subscriptionID);
|
||||
mkmethod1(fetchAllSubscriptions);
|
||||
mkmethod2(saveSubscription:(CKSubscription *)subscription);
|
||||
mkmethod2(deleteSubscriptionWithID:(NSString *)subscriptionID);
|
||||
#endif
|
||||
|
||||
@end
|
||||
91
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+Promise.swift
vendored
Normal file
91
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/CKDatabase+Promise.swift
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
import CloudKit.CKDatabase
|
||||
#if !PMKCocoaPods
|
||||
import PromiseKit
|
||||
#endif
|
||||
|
||||
#if swift(>=4.2)
|
||||
#else
|
||||
public extension CKRecordZone {
|
||||
typealias ID = CKRecordZoneID
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
To import the `CKDatabase` category:
|
||||
|
||||
use_frameworks!
|
||||
pod "PromiseKit/CloudKit"
|
||||
|
||||
And then in your sources:
|
||||
|
||||
@import PromiseKit;
|
||||
*/
|
||||
extension CKDatabase {
|
||||
/// Fetches one record asynchronously from the current database.
|
||||
public func fetch(withRecordID recordID: CKRecord.ID) -> Promise<CKRecord> {
|
||||
return Promise { fetch(withRecordID: recordID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Fetches one record zone asynchronously from the current database.
|
||||
public func fetch(withRecordZoneID recordZoneID: CKRecordZone.ID) -> Promise<CKRecordZone> {
|
||||
return Promise { fetch(withRecordZoneID: recordZoneID, completionHandler: $0.resolve) }
|
||||
}
|
||||
/// Fetches all record zones asynchronously from the current database.
|
||||
public func fetchAllRecordZones() -> Promise<[CKRecordZone]> {
|
||||
return Promise { fetchAllRecordZones(completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Saves one record zone asynchronously to the current database.
|
||||
public func save(_ record: CKRecord) -> Promise<CKRecord> {
|
||||
return Promise { save(record, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Saves one record zone asynchronously to the current database.
|
||||
public func save(_ recordZone: CKRecordZone) -> Promise<CKRecordZone> {
|
||||
return Promise { save(recordZone, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
public func delete(withRecordID recordID: CKRecord.ID) -> Promise<CKRecord.ID> {
|
||||
return Promise { delete(withRecordID: recordID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
public func delete(withRecordZoneID zoneID: CKRecordZone.ID) -> Promise<CKRecordZone.ID> {
|
||||
return Promise { delete(withRecordZoneID: zoneID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Searches the specified zone asynchronously for records that match the query parameters.
|
||||
public func perform(_ query: CKQuery, inZoneWith zoneID: CKRecordZone.ID? = nil) -> Promise<[CKRecord]> {
|
||||
return Promise { perform(query, inZoneWith: zoneID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Fetches the record for the current user.
|
||||
public func fetchUserRecord(_ container: CKContainer = CKContainer.default()) -> Promise<CKRecord> {
|
||||
return container.fetchUserRecordID().then(on: nil) { uid in
|
||||
return self.fetch(withRecordID: uid)
|
||||
}
|
||||
}
|
||||
|
||||
#if !os(watchOS)
|
||||
/// Fetches one record zone asynchronously from the current database.
|
||||
public func fetch(withSubscriptionID subscriptionID: String) -> Promise<CKSubscription> {
|
||||
return Promise { fetch(withSubscriptionID: subscriptionID, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Fetches all subscription objects asynchronously from the current database.
|
||||
public func fetchAllSubscriptions() -> Promise<[CKSubscription]> {
|
||||
return Promise { fetchAllSubscriptions(completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Saves one subscription object asynchronously to the current database.
|
||||
public func save(_ subscription: CKSubscription) -> Promise<CKSubscription> {
|
||||
return Promise { save(subscription, completionHandler: $0.resolve) }
|
||||
}
|
||||
|
||||
/// Delete one subscription object asynchronously from the current database.
|
||||
public func delete(withSubscriptionID subscriptionID: String) -> Promise<String> {
|
||||
return Promise { delete(withSubscriptionID: subscriptionID, completionHandler: $0.resolve) }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
2
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/PMKCloudKit.h
vendored
Normal file
2
Carthage/Checkouts/PromiseKit/Extensions/CloudKit/Sources/PMKCloudKit.h
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
#import "CKContainer+AnyPromise.h"
|
||||
#import "CKDatabase+AnyPromise.h"
|
||||
Reference in New Issue
Block a user