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

CloudKit - Support for limiting change set size in a CKReference-safe manner #512

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LumberjackUser.temp.h
jazzy.markdown

## CocoaPods within Unit Tests
##
##
## Excluding Xcode-desktop which is used by travis-ci
##
Testing/Swift-desktop/Pods
Expand All @@ -41,3 +41,4 @@ Testing/Xcode-mobile/Pods
Testing/Xcode-tv/Pods
Testing/Xcode-watch/Pods

Signing.xcconfig
59 changes: 24 additions & 35 deletions Examples/CloudKitTodo/CloudKitTodo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
51EE553F951BF40945032BD5 /* libPods-CloudKitTodo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ABB1832E9FCC349F48EB4C9C /* libPods-CloudKitTodo.a */; };
B9A9B95423FAADC500A187DD /* DONOTREMOVE.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9A9B95323FAADC500A187DD /* DONOTREMOVE.swift */; };
DC212CE11F6D98F600C11BF0 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC212CE01F6D98F600C11BF0 /* CloudKit.framework */; };
DC6071471A33F3FF00207DE9 /* TodoCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DC6071461A33F3FF00207DE9 /* TodoCell.m */; };
DC60714A1A33FC3900207DE9 /* checkmark-off.png in Resources */ = {isa = PBXBuildFile; fileRef = DC6071481A33FC3900207DE9 /* checkmark-off.png */; };
Expand All @@ -30,6 +31,11 @@
/* Begin PBXFileReference section */
703B5BE0F88E9B9E927805E5 /* Pods-CloudKitTodo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CloudKitTodo.release.xcconfig"; path = "Pods/Target Support Files/Pods-CloudKitTodo/Pods-CloudKitTodo.release.xcconfig"; sourceTree = "<group>"; };
ABB1832E9FCC349F48EB4C9C /* libPods-CloudKitTodo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CloudKitTodo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
B9A9B94F23FAA7E400A187DD /* Signing.sample.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Signing.sample.xcconfig; sourceTree = "<group>"; };
B9A9B95023FAA8C600A187DD /* Signing.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Signing.xcconfig; sourceTree = "<group>"; };
B9A9B95123FAAA9500A187DD /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
B9A9B95223FAADC500A187DD /* CloudKitTodo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CloudKitTodo-Bridging-Header.h"; sourceTree = "<group>"; };
B9A9B95323FAADC500A187DD /* DONOTREMOVE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DONOTREMOVE.swift; sourceTree = "<group>"; };
DC212CE01F6D98F600C11BF0 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
DC6071451A33F3FF00207DE9 /* TodoCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TodoCell.h; sourceTree = "<group>"; };
DC6071461A33F3FF00207DE9 /* TodoCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TodoCell.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +94,7 @@
DCDE77121A3023E9001D8FCE = {
isa = PBXGroup;
children = (
B9A9B95123FAAA9500A187DD /* README.md */,
DCDE771D1A3023E9001D8FCE /* CloudKitTodo */,
DCDE776B1A3028EA001D8FCE /* Frameworks */,
DCDE771C1A3023E9001D8FCE /* Products */,
Expand Down Expand Up @@ -122,6 +129,10 @@
DCDE77681A302873001D8FCE /* CloudKitTodo.entitlements */,
DCDE771F1A3023E9001D8FCE /* Info.plist */,
DCDE77201A3023E9001D8FCE /* main.m */,
B9A9B94F23FAA7E400A187DD /* Signing.sample.xcconfig */,
B9A9B95023FAA8C600A187DD /* Signing.xcconfig */,
B9A9B95323FAADC500A187DD /* DONOTREMOVE.swift */,
B9A9B95223FAADC500A187DD /* CloudKitTodo-Bridging-Header.h */,
);
name = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -189,8 +200,6 @@
DCDE77171A3023E9001D8FCE /* Sources */,
DCDE77181A3023E9001D8FCE /* Frameworks */,
DCDE77191A3023E9001D8FCE /* Resources */,
A7E36A79EF95353C65F5D2B6 /* [CP] Embed Pods Frameworks */,
ED83D0453CE4BE42D9A22D78 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -212,7 +221,8 @@
TargetAttributes = {
DCDE771A1A3023E9001D8FCE = {
CreatedOnToolsVersion = 6.1;
DevelopmentTeam = VT5GYGYX83;
DevelopmentTeam = 8Y2R2YMCQT;
LastSwiftMigration = 1130;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
Expand All @@ -232,6 +242,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -279,36 +290,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
A7E36A79EF95353C65F5D2B6 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CloudKitTodo/Pods-CloudKitTodo-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
ED83D0453CE4BE42D9A22D78 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CloudKitTodo/Pods-CloudKitTodo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -318,6 +299,7 @@
files = (
DCDE78801A302B29001D8FCE /* MyDatabaseObject.m in Sources */,
DCDE77771A302A66001D8FCE /* RootViewController.m in Sources */,
B9A9B95423FAADC500A187DD /* DONOTREMOVE.swift in Sources */,
DCDE77701A302A44001D8FCE /* CloudKitManager.m in Sources */,
DCDE77761A302A66001D8FCE /* EditViewController.m in Sources */,
DC927FFD1A344BA500FEEAEA /* TodoTextView.m in Sources */,
Expand Down Expand Up @@ -353,6 +335,7 @@
/* Begin XCBuildConfiguration section */
DCDE773C1A3023E9001D8FCE /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B9A9B95023FAA8C600A187DD /* Signing.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -405,6 +388,7 @@
};
DCDE773D1A3023E9001D8FCE /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B9A9B95023FAA8C600A187DD /* Signing.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -453,6 +437,7 @@
baseConfigurationReference = F32EDD3AE8334674ADF30C82 /* Pods-CloudKitTodo.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = CloudKitTodo/CloudKitTodo.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -466,9 +451,11 @@
);
INFOPLIST_FILE = CloudKitTodo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.4th-a.CloudKitTodo";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "CloudKitTodo/CloudKitTodo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -477,6 +464,7 @@
baseConfigurationReference = 703B5BE0F88E9B9E927805E5 /* Pods-CloudKitTodo.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = CloudKitTodo/CloudKitTodo.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -490,9 +478,10 @@
);
INFOPLIST_FILE = CloudKitTodo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.4th-a.CloudKitTodo";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "CloudKitTodo/CloudKitTodo-Bridging-Header.h";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
52 changes: 27 additions & 25 deletions Examples/CloudKitTodo/CloudKitTodo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,33 @@ - (id)init
[DDLog addLogger:[DDTTYLogger sharedInstance]];

[[DDTTYLogger sharedInstance] setColorsEnabled:YES];

#if TARGET_OS_IPHONE
UIColor *redColor = [UIColor redColor];
UIColor *orangeColor = [UIColor orangeColor];
UIColor *grayColor = [UIColor grayColor];
#else
NSColor *redColor = [NSColor redColor];
NSColor *orangeColor = [NSColor orangeColor];
NSColor *grayColor = [NSColor grayColor];
#endif

[[DDTTYLogger sharedInstance] setForegroundColor:redColor
backgroundColor:nil
forFlag:YDB_LOG_FLAG_ERROR // errors
context:YDBLogContext]; // from YapDatabase

[[DDTTYLogger sharedInstance] setForegroundColor:orangeColor
backgroundColor:nil
forFlag:YDB_LOG_FLAG_WARN // warnings
context:YDBLogContext]; // from YapDatabase

[[DDTTYLogger sharedInstance] setForegroundColor:grayColor
backgroundColor:nil
forFlag:YDB_LOG_FLAG_TRACE // trace (method invocations)
context:YDBLogContext]; // from YapDatabase

// TODO: Restore if/when https://github.com/yapstudios/YapDatabase/issues/509 is resolved
// #if TARGET_OS_IPHONE
// UIColor *redColor = [UIColor redColor];
// UIColor *orangeColor = [UIColor orangeColor];
// UIColor *grayColor = [UIColor grayColor];
// #else
// NSColor *redColor = [NSColor redColor];
// NSColor *orangeColor = [NSColor orangeColor];
// NSColor *grayColor = [NSColor grayColor];
// #endif
//
// [[DDTTYLogger sharedInstance] setForegroundColor:redColor
// backgroundColor:nil
// forFlag:YDBLogFlagError // errors
// context:YDBLogContext]; // from YapDatabase
//
// [[DDTTYLogger sharedInstance] setForegroundColor:orangeColor
// backgroundColor:nil
// forFlag:YDBLogFlagWarn // warnings
// context:YDBLogContext]; // from YapDatabase
//
// [[DDTTYLogger sharedInstance] setForegroundColor:grayColor
// backgroundColor:nil
// forFlag:YDBLogFlagTrace // trace (method invocations)
// context:YDBLogContext]; // from YapDatabase
// ^^^^^ TODO: Restore if/when https://github.com/yapstudios/YapDatabase/issues/509 is resolved
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

6 changes: 6 additions & 0 deletions Examples/CloudKitTodo/CloudKitTodo/DONOTREMOVE.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
///
/// Created by George Cox on 2/17/20.
///

/// Without any Swift files in the target, Xcode throws tons of errors about not
/// being able to find Swift core libs.
2 changes: 1 addition & 1 deletion Examples/CloudKitTodo/CloudKitTodo/DatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern DatabaseManager *MyDatabaseManager;
/**
* The path of the raw database file.
**/
+ (NSString *)databasePath;
+ (NSURL *)databaseURL;

/**
* The root database class, and extension(s)
Expand Down
36 changes: 21 additions & 15 deletions Examples/CloudKitTodo/CloudKitTodo/DatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ + (instancetype)sharedInstance
return MyDatabaseManager;
}

+ (NSString *)databasePath
+ (NSURL *)databaseURL
{
NSString *databaseName = @"MyAwesomeApp.sqlite";

Expand All @@ -56,9 +56,7 @@ + (NSString *)databasePath
create:YES
error:NULL];

NSURL *databaseURL = [baseURL URLByAppendingPathComponent:databaseName isDirectory:NO];

return databaseURL.filePathURL.path;
return [baseURL URLByAppendingPathComponent:databaseName isDirectory:NO];
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -149,8 +147,8 @@ - (YapDatabasePostSanitizer)databasePostSanitizer

- (void)setupDatabase
{
NSString *databasePath = [[self class] databasePath];
DDLogVerbose(@"databasePath: %@", databasePath);
NSURL *databaseURL = [[self class] databaseURL];
DDLogVerbose(@"databaseURL: %@", databaseURL);

// Configure custom class mappings for NSCoding.
// In a previous version of the app, the "MyTodo" class was named "MyTodoItem".
Expand All @@ -159,21 +157,29 @@ - (void)setupDatabase
[NSKeyedUnarchiver setClass:[MyTodo class] forClassName:@"MyTodoItem"];

// Create the database

database = [[YapDatabase alloc] initWithPath:databasePath
serializer:[self databaseSerializer]
deserializer:[self databaseDeserializer]
preSanitizer:[self databasePreSanitizer]
postSanitizer:[self databasePostSanitizer]
options:nil];
database = [[YapDatabase alloc] initWithURL:databaseURL options:nil];
[database registerDefaultSerializer:[self databaseSerializer]];
[database registerDefaultDeserializer:[self databaseDeserializer]];
[database registerDefaultPreSanitizer:[self databasePreSanitizer]];
[database registerDefaultPostSanitizer:[self databasePostSanitizer]];

// FOR ADVANCED USERS ONLY
//
// Do NOT copy this blindly into your app unless you know exactly what you're doing.
// https://github.com/yapstudios/YapDatabase/wiki/Object-Policy
//
database.defaultObjectPolicy = YapDatabasePolicyShare;
database.defaultMetadataPolicy = YapDatabasePolicyShare;
// TODO: Restore the following once https://github.com/yapstudios/YapDatabase/issues/502 is resolved
// database.defaultObjectPolicy = YapDatabasePolicyShare;
// database.defaultMetadataPolicy = YapDatabasePolicyShare;
// TODO: Remove the following once https://github.com/yapstudios/YapDatabase/issues/502 is resolved
[database setObjectPolicy:YapDatabasePolicyShare forCollection:Collection_CloudKit];
[database setObjectPolicy:YapDatabasePolicyShare forCollection:Collection_Todos];
[database setObjectPolicy:YapDatabasePolicyShare forCollection:nil];
[database setMetadataPolicy:YapDatabasePolicyShare forCollection:Collection_CloudKit];
[database setMetadataPolicy:YapDatabasePolicyShare forCollection:Collection_Todos];
[database setMetadataPolicy:YapDatabasePolicyShare forCollection:nil];
// ^^^ TODO: Remove the following once https://github.com/yapstudios/YapDatabase/issues/502 is resolved

//
// ^^^ FOR ADVANCED USERS ONLY ^^^

Expand Down
5 changes: 3 additions & 2 deletions Examples/CloudKitTodo/CloudKitTodo/EditViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ - (void)saveButtonTapped:(id)sender
newPriority = TodoPriorityHigh;
else
newPriority = TodoPriorityNormal;


NSString *uuidLabelText = uuidLabel.text;
[MyDatabaseManager.bgDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {

MyTodo *todo = [transaction objectForKey:todoID inCollection:Collection_Todos];

if (todo == nil)
{
todo = [[MyTodo alloc] initWithUUID:uuidLabel.text];
todo = [[MyTodo alloc] initWithUUID:uuidLabelText];

todo.title = newTitle;
todo.isDone = newIsDone;
Expand Down
13 changes: 13 additions & 0 deletions Examples/CloudKitTodo/CloudKitTodo/Signing.sample.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///
/// Created by George Cox on 2/17/20.
///

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

// This is a sample xcconfig file. The point is to remove the hard coded signing
// information from the project so anyone trying to use this can add their own
// Signing.xcconfig file with their own team id and bundle id

DEVELOPMENT_TEAM = <your team id here>
PRODUCT_BUNDLE_IDENTIFIER = <your domain>.ydb.cktodo
3 changes: 2 additions & 1 deletion Examples/CloudKitTodo/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
platform :ios, '10.0'

target 'CloudKitTodo' do
pod 'Reachability', '3.2'
pod 'Reachability', '3.2'
pod 'CocoaLumberjack'
pod "YapDatabase", path: '../../'
end
Loading