├── .gitignore ├── CloudKitchenSink.xcodeproj └── project.pbxproj ├── CloudKitchenSink ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CloudKitchenSink.entitlements ├── Info.plist ├── Localizable.strings ├── QueryTableViewController.swift ├── QueryTypeSelectorTableViewController.swift ├── SimpleRecordTableViewController.swift ├── SubscriptionViewController.swift ├── UserViewController.swift └── pt-BR.lproj │ ├── LaunchScreen.strings │ └── Main.strings ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | __MACOSX 3 | *.pbxuser 4 | !default.pbxuser 5 | *.mode1v3 6 | !default.mode1v3 7 | *.mode2v3 8 | !default.mode2v3 9 | *.perspectivev3 10 | !default.perspectivev3 11 | *.xcworkspace 12 | !default.xcworkspace 13 | xcuserdata 14 | profile 15 | *.moved-aside 16 | DerivedData 17 | .idea/ 18 | Crashlytics.sh 19 | generatechangelog.sh 20 | Pods/ 21 | Carthage -------------------------------------------------------------------------------- /CloudKitchenSink.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DD0745001E7ED46E00C231DE /* SubscriptionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD0744FF1E7ED46E00C231DE /* SubscriptionViewController.swift */; }; 11 | DD23C1431E7EDE49009E0F24 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = DD23C1421E7EDE49009E0F24 /* Localizable.strings */; }; 12 | DD501A611E75BE6D00EBD001 /* QueryTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD501A601E75BE6D00EBD001 /* QueryTableViewController.swift */; }; 13 | DD501A631E75BF7700EBD001 /* QueryTypeSelectorTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD501A621E75BF7700EBD001 /* QueryTypeSelectorTableViewController.swift */; }; 14 | DD96F4111E6C4BA500CABB08 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD96F4101E6C4BA500CABB08 /* AppDelegate.swift */; }; 15 | DD96F4131E6C4BA500CABB08 /* UserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD96F4121E6C4BA500CABB08 /* UserViewController.swift */; }; 16 | DD96F4161E6C4BA500CABB08 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DD96F4141E6C4BA500CABB08 /* Main.storyboard */; }; 17 | DD96F4181E6C4BA500CABB08 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DD96F4171E6C4BA500CABB08 /* Assets.xcassets */; }; 18 | DD96F41B1E6C4BA500CABB08 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DD96F4191E6C4BA500CABB08 /* LaunchScreen.storyboard */; }; 19 | DD96F4251E6C4BE200CABB08 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD96F4241E6C4BE200CABB08 /* CloudKit.framework */; }; 20 | DD96F42C1E6C59ED00CABB08 /* SimpleRecordTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD96F42B1E6C59ED00CABB08 /* SimpleRecordTableViewController.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXFileReference section */ 24 | DD0744FF1E7ED46E00C231DE /* SubscriptionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptionViewController.swift; sourceTree = ""; }; 25 | DD23C1401E7EDDDE009E0F24 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Main.strings"; sourceTree = ""; }; 26 | DD23C1411E7EDDDE009E0F24 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/LaunchScreen.strings"; sourceTree = ""; }; 27 | DD23C1421E7EDE49009E0F24 /* Localizable.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = Localizable.strings; sourceTree = ""; }; 28 | DD501A601E75BE6D00EBD001 /* QueryTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTableViewController.swift; sourceTree = ""; }; 29 | DD501A621E75BF7700EBD001 /* QueryTypeSelectorTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTypeSelectorTableViewController.swift; sourceTree = ""; }; 30 | DD96F40D1E6C4BA500CABB08 /* CloudKitchenSink.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CloudKitchenSink.app; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | DD96F4101E6C4BA500CABB08 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 32 | DD96F4121E6C4BA500CABB08 /* UserViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserViewController.swift; sourceTree = ""; }; 33 | DD96F4151E6C4BA500CABB08 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | DD96F4171E6C4BA500CABB08 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 35 | DD96F41A1E6C4BA500CABB08 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 36 | DD96F41C1E6C4BA500CABB08 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | DD96F4221E6C4BDE00CABB08 /* CloudKitchenSink.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CloudKitchenSink.entitlements; sourceTree = ""; }; 38 | DD96F4241E6C4BE200CABB08 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; 39 | DD96F42B1E6C59ED00CABB08 /* SimpleRecordTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleRecordTableViewController.swift; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | DD96F40A1E6C4BA500CABB08 /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | DD96F4251E6C4BE200CABB08 /* CloudKit.framework in Frameworks */, 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | DD96F4041E6C4BA500CABB08 = { 55 | isa = PBXGroup; 56 | children = ( 57 | DD96F40F1E6C4BA500CABB08 /* CloudKitchenSink */, 58 | DD96F40E1E6C4BA500CABB08 /* Products */, 59 | DD96F4231E6C4BE200CABB08 /* Frameworks */, 60 | ); 61 | sourceTree = ""; 62 | }; 63 | DD96F40E1E6C4BA500CABB08 /* Products */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | DD96F40D1E6C4BA500CABB08 /* CloudKitchenSink.app */, 67 | ); 68 | name = Products; 69 | sourceTree = ""; 70 | }; 71 | DD96F40F1E6C4BA500CABB08 /* CloudKitchenSink */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | DD96F4221E6C4BDE00CABB08 /* CloudKitchenSink.entitlements */, 75 | DD96F4281E6C4D8300CABB08 /* Bootstrap */, 76 | DD96F4261E6C4D6B00CABB08 /* Resources */, 77 | DD96F4271E6C4D7900CABB08 /* Controllers */, 78 | ); 79 | path = CloudKitchenSink; 80 | sourceTree = ""; 81 | }; 82 | DD96F4231E6C4BE200CABB08 /* Frameworks */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | DD96F4241E6C4BE200CABB08 /* CloudKit.framework */, 86 | ); 87 | name = Frameworks; 88 | sourceTree = ""; 89 | }; 90 | DD96F4261E6C4D6B00CABB08 /* Resources */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | DD23C1421E7EDE49009E0F24 /* Localizable.strings */, 94 | DD96F4141E6C4BA500CABB08 /* Main.storyboard */, 95 | DD96F4171E6C4BA500CABB08 /* Assets.xcassets */, 96 | DD96F4191E6C4BA500CABB08 /* LaunchScreen.storyboard */, 97 | DD96F41C1E6C4BA500CABB08 /* Info.plist */, 98 | ); 99 | name = Resources; 100 | sourceTree = ""; 101 | }; 102 | DD96F4271E6C4D7900CABB08 /* Controllers */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | DD96F4121E6C4BA500CABB08 /* UserViewController.swift */, 106 | DD96F42B1E6C59ED00CABB08 /* SimpleRecordTableViewController.swift */, 107 | DD501A621E75BF7700EBD001 /* QueryTypeSelectorTableViewController.swift */, 108 | DD501A601E75BE6D00EBD001 /* QueryTableViewController.swift */, 109 | DD0744FF1E7ED46E00C231DE /* SubscriptionViewController.swift */, 110 | ); 111 | name = Controllers; 112 | sourceTree = ""; 113 | }; 114 | DD96F4281E6C4D8300CABB08 /* Bootstrap */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | DD96F4101E6C4BA500CABB08 /* AppDelegate.swift */, 118 | ); 119 | name = Bootstrap; 120 | sourceTree = ""; 121 | }; 122 | /* End PBXGroup section */ 123 | 124 | /* Begin PBXNativeTarget section */ 125 | DD96F40C1E6C4BA500CABB08 /* CloudKitchenSink */ = { 126 | isa = PBXNativeTarget; 127 | buildConfigurationList = DD96F41F1E6C4BA500CABB08 /* Build configuration list for PBXNativeTarget "CloudKitchenSink" */; 128 | buildPhases = ( 129 | DD96F4091E6C4BA500CABB08 /* Sources */, 130 | DD96F40A1E6C4BA500CABB08 /* Frameworks */, 131 | DD96F40B1E6C4BA500CABB08 /* Resources */, 132 | ); 133 | buildRules = ( 134 | ); 135 | dependencies = ( 136 | ); 137 | name = CloudKitchenSink; 138 | productName = CloudKitchenSink; 139 | productReference = DD96F40D1E6C4BA500CABB08 /* CloudKitchenSink.app */; 140 | productType = "com.apple.product-type.application"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | DD96F4051E6C4BA500CABB08 /* Project object */ = { 146 | isa = PBXProject; 147 | attributes = { 148 | LastSwiftUpdateCheck = 0820; 149 | LastUpgradeCheck = 0820; 150 | ORGANIZATIONNAME = "Guilherme Rambo"; 151 | TargetAttributes = { 152 | DD96F40C1E6C4BA500CABB08 = { 153 | CreatedOnToolsVersion = 8.2.1; 154 | DevelopmentTeam = 8C7439RJLG; 155 | ProvisioningStyle = Automatic; 156 | SystemCapabilities = { 157 | com.apple.Push = { 158 | enabled = 1; 159 | }; 160 | com.apple.iCloud = { 161 | enabled = 1; 162 | }; 163 | }; 164 | }; 165 | }; 166 | }; 167 | buildConfigurationList = DD96F4081E6C4BA500CABB08 /* Build configuration list for PBXProject "CloudKitchenSink" */; 168 | compatibilityVersion = "Xcode 3.2"; 169 | developmentRegion = English; 170 | hasScannedForEncodings = 0; 171 | knownRegions = ( 172 | en, 173 | Base, 174 | ); 175 | mainGroup = DD96F4041E6C4BA500CABB08; 176 | productRefGroup = DD96F40E1E6C4BA500CABB08 /* Products */; 177 | projectDirPath = ""; 178 | projectRoot = ""; 179 | targets = ( 180 | DD96F40C1E6C4BA500CABB08 /* CloudKitchenSink */, 181 | ); 182 | }; 183 | /* End PBXProject section */ 184 | 185 | /* Begin PBXResourcesBuildPhase section */ 186 | DD96F40B1E6C4BA500CABB08 /* Resources */ = { 187 | isa = PBXResourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | DD96F41B1E6C4BA500CABB08 /* LaunchScreen.storyboard in Resources */, 191 | DD23C1431E7EDE49009E0F24 /* Localizable.strings in Resources */, 192 | DD96F4181E6C4BA500CABB08 /* Assets.xcassets in Resources */, 193 | DD96F4161E6C4BA500CABB08 /* Main.storyboard in Resources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXResourcesBuildPhase section */ 198 | 199 | /* Begin PBXSourcesBuildPhase section */ 200 | DD96F4091E6C4BA500CABB08 /* Sources */ = { 201 | isa = PBXSourcesBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | DD0745001E7ED46E00C231DE /* SubscriptionViewController.swift in Sources */, 205 | DD96F42C1E6C59ED00CABB08 /* SimpleRecordTableViewController.swift in Sources */, 206 | DD96F4131E6C4BA500CABB08 /* UserViewController.swift in Sources */, 207 | DD96F4111E6C4BA500CABB08 /* AppDelegate.swift in Sources */, 208 | DD501A611E75BE6D00EBD001 /* QueryTableViewController.swift in Sources */, 209 | DD501A631E75BF7700EBD001 /* QueryTypeSelectorTableViewController.swift in Sources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | /* End PBXSourcesBuildPhase section */ 214 | 215 | /* Begin PBXVariantGroup section */ 216 | DD96F4141E6C4BA500CABB08 /* Main.storyboard */ = { 217 | isa = PBXVariantGroup; 218 | children = ( 219 | DD96F4151E6C4BA500CABB08 /* Base */, 220 | DD23C1401E7EDDDE009E0F24 /* pt-BR */, 221 | ); 222 | name = Main.storyboard; 223 | sourceTree = ""; 224 | }; 225 | DD96F4191E6C4BA500CABB08 /* LaunchScreen.storyboard */ = { 226 | isa = PBXVariantGroup; 227 | children = ( 228 | DD96F41A1E6C4BA500CABB08 /* Base */, 229 | DD23C1411E7EDDDE009E0F24 /* pt-BR */, 230 | ); 231 | name = LaunchScreen.storyboard; 232 | sourceTree = ""; 233 | }; 234 | /* End PBXVariantGroup section */ 235 | 236 | /* Begin XCBuildConfiguration section */ 237 | DD96F41D1E6C4BA500CABB08 /* Debug */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 242 | CLANG_ANALYZER_NONNULL = YES; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INFINITE_RECURSION = YES; 254 | CLANG_WARN_INT_CONVERSION = YES; 255 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 256 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 257 | CLANG_WARN_UNREACHABLE_CODE = YES; 258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 259 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 260 | COPY_PHASE_STRIP = NO; 261 | DEBUG_INFORMATION_FORMAT = dwarf; 262 | ENABLE_STRICT_OBJC_MSGSEND = YES; 263 | ENABLE_TESTABILITY = YES; 264 | GCC_C_LANGUAGE_STANDARD = gnu99; 265 | GCC_DYNAMIC_NO_PIC = NO; 266 | GCC_NO_COMMON_BLOCKS = YES; 267 | GCC_OPTIMIZATION_LEVEL = 0; 268 | GCC_PREPROCESSOR_DEFINITIONS = ( 269 | "DEBUG=1", 270 | "$(inherited)", 271 | ); 272 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 273 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 274 | GCC_WARN_UNDECLARED_SELECTOR = YES; 275 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 276 | GCC_WARN_UNUSED_FUNCTION = YES; 277 | GCC_WARN_UNUSED_VARIABLE = YES; 278 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 279 | MTL_ENABLE_DEBUG_INFO = YES; 280 | ONLY_ACTIVE_ARCH = YES; 281 | SDKROOT = iphoneos; 282 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 283 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 284 | TARGETED_DEVICE_FAMILY = "1,2"; 285 | }; 286 | name = Debug; 287 | }; 288 | DD96F41E1E6C4BA500CABB08 /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ALWAYS_SEARCH_USER_PATHS = NO; 292 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 293 | CLANG_ANALYZER_NONNULL = YES; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 302 | CLANG_WARN_EMPTY_BODY = YES; 303 | CLANG_WARN_ENUM_CONVERSION = YES; 304 | CLANG_WARN_INFINITE_RECURSION = YES; 305 | CLANG_WARN_INT_CONVERSION = YES; 306 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 307 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 308 | CLANG_WARN_UNREACHABLE_CODE = YES; 309 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 310 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 311 | COPY_PHASE_STRIP = NO; 312 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 313 | ENABLE_NS_ASSERTIONS = NO; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_NO_COMMON_BLOCKS = YES; 317 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 318 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 319 | GCC_WARN_UNDECLARED_SELECTOR = YES; 320 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 321 | GCC_WARN_UNUSED_FUNCTION = YES; 322 | GCC_WARN_UNUSED_VARIABLE = YES; 323 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 324 | MTL_ENABLE_DEBUG_INFO = NO; 325 | SDKROOT = iphoneos; 326 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | VALIDATE_PRODUCT = YES; 329 | }; 330 | name = Release; 331 | }; 332 | DD96F4201E6C4BA500CABB08 /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 336 | CODE_SIGN_ENTITLEMENTS = CloudKitchenSink/CloudKitchenSink.entitlements; 337 | DEVELOPMENT_TEAM = 8C7439RJLG; 338 | INFOPLIST_FILE = CloudKitchenSink/Info.plist; 339 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 340 | PRODUCT_BUNDLE_IDENTIFIER = br.com.guilhermerambo.CloudKitchenSink; 341 | PRODUCT_NAME = "$(TARGET_NAME)"; 342 | SWIFT_VERSION = 3.0; 343 | }; 344 | name = Debug; 345 | }; 346 | DD96F4211E6C4BA500CABB08 /* Release */ = { 347 | isa = XCBuildConfiguration; 348 | buildSettings = { 349 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 350 | CODE_SIGN_ENTITLEMENTS = CloudKitchenSink/CloudKitchenSink.entitlements; 351 | DEVELOPMENT_TEAM = 8C7439RJLG; 352 | INFOPLIST_FILE = CloudKitchenSink/Info.plist; 353 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 354 | PRODUCT_BUNDLE_IDENTIFIER = br.com.guilhermerambo.CloudKitchenSink; 355 | PRODUCT_NAME = "$(TARGET_NAME)"; 356 | SWIFT_VERSION = 3.0; 357 | }; 358 | name = Release; 359 | }; 360 | /* End XCBuildConfiguration section */ 361 | 362 | /* Begin XCConfigurationList section */ 363 | DD96F4081E6C4BA500CABB08 /* Build configuration list for PBXProject "CloudKitchenSink" */ = { 364 | isa = XCConfigurationList; 365 | buildConfigurations = ( 366 | DD96F41D1E6C4BA500CABB08 /* Debug */, 367 | DD96F41E1E6C4BA500CABB08 /* Release */, 368 | ); 369 | defaultConfigurationIsVisible = 0; 370 | defaultConfigurationName = Release; 371 | }; 372 | DD96F41F1E6C4BA500CABB08 /* Build configuration list for PBXNativeTarget "CloudKitchenSink" */ = { 373 | isa = XCConfigurationList; 374 | buildConfigurations = ( 375 | DD96F4201E6C4BA500CABB08 /* Debug */, 376 | DD96F4211E6C4BA500CABB08 /* Release */, 377 | ); 378 | defaultConfigurationIsVisible = 0; 379 | defaultConfigurationName = Release; 380 | }; 381 | /* End XCConfigurationList section */ 382 | }; 383 | rootObject = DD96F4051E6C4BA500CABB08 /* Project object */; 384 | } 385 | -------------------------------------------------------------------------------- /CloudKitchenSink/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 05/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CloudKit 11 | 12 | extension UIViewController { 13 | 14 | var container: CKContainer { 15 | return CKContainer(identifier: "iCloud.br.com.guilhermerambo.KitchenContainer") 16 | } 17 | 18 | } 19 | 20 | @UIApplicationMain 21 | class AppDelegate: UIResponder, UIApplicationDelegate { 22 | 23 | var window: UIWindow? 24 | 25 | 26 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 27 | configureCloudKit() 28 | 29 | return true 30 | } 31 | 32 | private func configureCloudKit() { 33 | let container = CKContainer(identifier: "iCloud.br.com.guilhermerambo.KitchenContainer") 34 | 35 | container.privateCloudDatabase.fetchAllRecordZones { zones, error in 36 | guard let zones = zones, error == nil else { 37 | // error handling magic 38 | return 39 | } 40 | 41 | print("I have these zones: \(zones)") 42 | } 43 | } 44 | 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /CloudKitchenSink/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CloudKitchenSink/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CloudKitchenSink/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 111 | 117 | 123 | 124 | 125 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 337 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 475 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 556 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | -------------------------------------------------------------------------------- /CloudKitchenSink/CloudKitchenSink.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | aps-environment 6 | development 7 | com.apple.developer.icloud-container-identifiers 8 | 9 | iCloud.$(CFBundleIdentifier) 10 | iCloud.br.com.guilhermerambo.KitchenContainer 11 | 12 | com.apple.developer.icloud-services 13 | 14 | CloudKit 15 | 16 | com.apple.developer.ubiquity-kvstore-identifier 17 | $(TeamIdentifierPrefix)$(CFBundleIdentifier) 18 | 19 | 20 | -------------------------------------------------------------------------------- /CloudKitchenSink/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | CloudKitchenSink 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSCameraUsageDescription 26 | We need to access the camera so you can take a picture for your avatar 27 | NSLocationWhenInUseUsageDescription 28 | We need your location to find movies shot near you 29 | NSPhotoLibraryUsageDescription 30 | We need access to your photos to change your avatar 31 | UILaunchStoryboardName 32 | LaunchScreen 33 | UIMainStoryboardFile 34 | Main 35 | UIRequiredDeviceCapabilities 36 | 37 | armv7 38 | 39 | UISupportedInterfaceOrientations 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationLandscapeLeft 43 | UIInterfaceOrientationLandscapeRight 44 | 45 | UISupportedInterfaceOrientations~ipad 46 | 47 | UIInterfaceOrientationPortrait 48 | UIInterfaceOrientationPortraitUpsideDown 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /CloudKitchenSink/Localizable.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insidegui/CloudKitchenSink/c56412579f7c8e833821de0520726009ea5f7bf0/CloudKitchenSink/Localizable.strings -------------------------------------------------------------------------------- /CloudKitchenSink/QueryTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // QueryTableViewController.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 12/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CloudKit 11 | import CoreLocation 12 | 13 | enum QueryType: String { 14 | 15 | case all 16 | case title 17 | case location 18 | 19 | var title: String { 20 | switch self { 21 | case .all: 22 | return "All Records" 23 | case .title: 24 | return "Search by Title" 25 | case .location: 26 | return "Search by Location" 27 | } 28 | } 29 | 30 | } 31 | 32 | final class QueryTableViewController: UITableViewController { 33 | 34 | @IBOutlet weak var searchContainer: UIStackView! 35 | @IBOutlet weak var textField: UITextField! 36 | @IBOutlet weak var searchButton: UIButton! 37 | 38 | fileprivate var currentLocation: CLLocation? { 39 | didSet { 40 | DispatchQueue.main.async { 41 | self.search(self) 42 | } 43 | } 44 | } 45 | 46 | fileprivate var movies: [CKRecord] = [] { 47 | didSet { 48 | tableView.reloadSections([0], with: .automatic) 49 | } 50 | } 51 | 52 | var queryType: QueryType? { 53 | didSet { 54 | guard let queryType = queryType else { return } 55 | 56 | title = queryType.title 57 | } 58 | } 59 | 60 | override func viewDidLoad() { 61 | super.viewDidLoad() 62 | } 63 | 64 | override func viewWillAppear(_ animated: Bool) { 65 | super.viewWillAppear(animated) 66 | 67 | guard let queryType = queryType else { return } 68 | 69 | if queryType != .title { 70 | tableView.tableHeaderView = nil 71 | search(self) 72 | } else { 73 | _ = textField.becomeFirstResponder() 74 | } 75 | } 76 | 77 | private lazy var locationManager: CLLocationManager = { 78 | let m = CLLocationManager() 79 | 80 | m.distanceFilter = kCLDistanceFilterNone 81 | m.desiredAccuracy = kCLLocationAccuracyThreeKilometers 82 | m.delegate = self 83 | 84 | return m 85 | }() 86 | 87 | override func viewDidAppear(_ animated: Bool) { 88 | super.viewDidAppear(animated) 89 | 90 | locationManager.requestWhenInUseAuthorization() 91 | locationManager.requestLocation() 92 | } 93 | 94 | private func predicate(with title: String) -> NSPredicate { 95 | return NSPredicate(format: "self contains %@", title) 96 | } 97 | 98 | private func predicate(closeTo location: CLLocation, radius: Float = 500.0) -> NSPredicate { 99 | return NSPredicate(format: "distanceToLocation:fromLocation:(location, %@) < %f", location, radius) 100 | } 101 | 102 | private func predicateForAll() -> NSPredicate { 103 | return NSPredicate(value: true) 104 | } 105 | 106 | private var currentOperation: CKDatabaseOperation? 107 | 108 | fileprivate func showLocationAlert() { 109 | let alert = UIAlertController(title: "No Location", message: "Sorry, I don't know your location", preferredStyle: .alert) 110 | alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) 111 | 112 | present(alert, animated: true, completion: nil) 113 | } 114 | 115 | @IBAction func search(_ sender: Any) { 116 | guard let queryType = self.queryType else { return } 117 | 118 | currentOperation?.cancel() 119 | 120 | let predicate: NSPredicate 121 | 122 | switch queryType { 123 | case .all: 124 | predicate = self.predicateForAll() 125 | case .title: 126 | predicate = self.predicate(with: textField.text ?? "") 127 | case .location: 128 | if let location = currentLocation { 129 | predicate = self.predicate(closeTo: location) 130 | } else { 131 | // wait for the location to become available 132 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 133 | return 134 | } 135 | } 136 | 137 | let query = CKQuery(recordType: "Movie", predicate: predicate) 138 | 139 | self.perform(query: query) { [weak self] movieRecords, error in 140 | self?.movies = movieRecords 141 | } 142 | } 143 | 144 | private var fetchedRecords: [CKRecord] = [] 145 | 146 | private func perform(query: CKQuery, inputCursor: CKQueryCursor? = nil, completion: @escaping ([CKRecord], Error?) -> Void) { 147 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 148 | searchButton?.isEnabled = false 149 | 150 | let operation: CKQueryOperation 151 | 152 | if let inputCursor = inputCursor { 153 | operation = CKQueryOperation(cursor: inputCursor) 154 | } else { 155 | operation = CKQueryOperation(query: query) 156 | } 157 | 158 | operation.recordFetchedBlock = { [weak self] record in 159 | self?.fetchedRecords.append(record) 160 | } 161 | 162 | operation.queryCompletionBlock = { [weak self] cursor, error in 163 | guard let welf = self else { return } 164 | 165 | DispatchQueue.main.async { 166 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 167 | welf.searchButton?.isEnabled = true 168 | 169 | welf.currentOperation = nil 170 | 171 | if let cursor = cursor { 172 | welf.perform(query: query, inputCursor: cursor, completion: completion) 173 | } else { 174 | completion(welf.fetchedRecords, nil) 175 | welf.fetchedRecords = [] 176 | } 177 | } 178 | } 179 | 180 | container.publicCloudDatabase.add(operation) 181 | 182 | currentOperation = operation 183 | } 184 | 185 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 186 | return movies.count 187 | } 188 | 189 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 190 | let cell = tableView.dequeueReusableCell(withIdentifier: "movie") 191 | 192 | cell?.textLabel?.text = movies[indexPath.row]["title"] as? String ?? "" 193 | 194 | if let date = movies[indexPath.row]["releaseDate"] as? Date { 195 | let formatter = DateFormatter() 196 | formatter.dateStyle = .medium 197 | cell?.detailTextLabel?.text = formatter.string(from: date) 198 | } 199 | 200 | return cell ?? UITableViewCell() 201 | } 202 | 203 | } 204 | 205 | extension QueryTableViewController: CLLocationManagerDelegate { 206 | 207 | func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 208 | guard let location = locations.first else { return } 209 | 210 | self.currentLocation = location 211 | } 212 | 213 | func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 214 | DispatchQueue.main.async { 215 | self.showLocationAlert() 216 | } 217 | } 218 | 219 | } 220 | -------------------------------------------------------------------------------- /CloudKitchenSink/QueryTypeSelectorTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // QueryTypeSelectorTableViewController.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 12/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class QueryTypeSelectorTableViewController: UITableViewController { 12 | 13 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 14 | guard let identifier = segue.identifier, let queryType = QueryType(rawValue: identifier) else { 15 | fatalError("Unknown query type \(String(describing: segue.identifier))") 16 | } 17 | 18 | guard let destination = segue.destination as? QueryTableViewController else { 19 | fatalError("Query type segue destination must be a QueryTableViewController") 20 | } 21 | 22 | destination.queryType = queryType 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /CloudKitchenSink/SimpleRecordTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SimpleRecordTableViewController.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 05/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CloudKit 11 | import CoreLocation 12 | 13 | enum MovieKey: String { 14 | case title 15 | case releaseDate 16 | case location 17 | case rating 18 | } 19 | 20 | extension CKRecord { 21 | 22 | subscript(key: MovieKey) -> Any? { 23 | get { 24 | return self[key.rawValue] 25 | } 26 | set { 27 | self[key.rawValue] = newValue as? CKRecordValue 28 | } 29 | } 30 | 31 | } 32 | 33 | extension String { 34 | 35 | init?(_ placemark: CLPlacemark) { 36 | guard let country = placemark.country, let locality = placemark.locality else { return nil } 37 | 38 | self = "\(locality), \(country)" 39 | } 40 | 41 | } 42 | 43 | class SimpleRecordTableViewController: UITableViewController { 44 | 45 | @IBOutlet weak var titleField: UITextField! 46 | @IBOutlet weak var dateField: UITextField! 47 | @IBOutlet weak var locationField: UITextField! 48 | @IBOutlet weak var ratingSlider: UISlider! 49 | @IBOutlet weak var saveButton: UIButton! 50 | @IBOutlet weak var activityIndicator: UIActivityIndicatorView! 51 | 52 | var record = CKRecord(recordType: "Movie") 53 | 54 | override func viewDidLoad() { 55 | super.viewDidLoad() 56 | } 57 | 58 | @IBAction func titleFieldAction(_ sender: Any) { 59 | guard let title = titleField.text else { return } 60 | 61 | record[.title] = title 62 | } 63 | 64 | @IBAction func releaseDateFieldAction(_ sender: Any) { 65 | guard let dateString = dateField.text else { return } 66 | 67 | let formatter = DateFormatter() 68 | formatter.dateFormat = "yyyy-MM-dd" 69 | 70 | guard let date = formatter.date(from: dateString) else { return } 71 | 72 | record[.releaseDate] = date 73 | } 74 | 75 | @IBAction func locationFieldAction(_ sender: Any) { 76 | guard let locationString = locationField.text else { return } 77 | 78 | CLGeocoder().geocodeAddressString(locationString) { placemarks, error in 79 | guard let placemark = placemarks?.first, error == nil else { return } 80 | 81 | self.record[.location] = placemark.location 82 | 83 | DispatchQueue.main.async { 84 | self.locationField.text = String(placemark) 85 | } 86 | } 87 | } 88 | 89 | @IBAction func ratingSliderAction(_ sender: Any) { 90 | let value = Int(ceil(ratingSlider.value)) 91 | 92 | record[.rating] = value 93 | } 94 | 95 | @IBAction func save(_ sender: Any) { 96 | saveButton.isEnabled = false 97 | saveButton.isHidden = true 98 | activityIndicator.startAnimating() 99 | 100 | container.publicCloudDatabase.save(record) { [unowned self] _, error in 101 | DispatchQueue.main.async { 102 | self.activityIndicator.stopAnimating() 103 | self.saveButton.isEnabled = true 104 | self.saveButton.isHidden = false 105 | 106 | if let error = error { 107 | let alert = UIAlertController(title: "CloudKit error", message: error.localizedDescription, preferredStyle: .alert) 108 | alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) 109 | self.present(alert, animated: true, completion: nil) 110 | } else { 111 | self.clear() 112 | } 113 | } 114 | } 115 | } 116 | 117 | private func clear() { 118 | titleField.text = nil 119 | dateField.text = nil 120 | locationField.text = nil 121 | ratingSlider.value = 0 122 | 123 | record = CKRecord(recordType: "Movie") 124 | 125 | _ = titleField.becomeFirstResponder() 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /CloudKitchenSink/SubscriptionViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SubscriptionViewController.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 19/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CloudKit 11 | import UserNotifications 12 | 13 | class SubscriptionViewController: UIViewController { 14 | 15 | @IBOutlet weak var subscribeButton: UIButton! 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | checkSubscriptionStatus() 21 | } 22 | 23 | fileprivate var isSubscribed = false { 24 | didSet { 25 | subscribeButton.setTitle(isSubscribed ? "Cancel Subscription" : "Subscribe", for: .normal) 26 | } 27 | } 28 | 29 | fileprivate var subscriptionID: String? { 30 | get { 31 | return UserDefaults.standard.object(forKey: "subscriptionID") as? String 32 | } 33 | set { 34 | UserDefaults.standard.set(newValue, forKey: "subscriptionID") 35 | } 36 | } 37 | 38 | fileprivate func checkSubscriptionStatus() { 39 | isSubscribed = subscriptionID != nil 40 | } 41 | 42 | fileprivate func createSubscription() { 43 | subscribeButton.isEnabled = false 44 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 45 | 46 | UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { authorized, error in 47 | DispatchQueue.main.async { 48 | guard error == nil, authorized else { 49 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 50 | 51 | let alert = UIAlertController(title: "Not Authorized", message: "We need permission to show you notifications", preferredStyle: .alert) 52 | 53 | alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) 54 | self.present(alert, animated: true, completion: nil) 55 | 56 | return 57 | } 58 | 59 | self.saveSubscription() 60 | } 61 | } 62 | UIApplication.shared.registerForRemoteNotifications() 63 | } 64 | 65 | fileprivate func saveSubscription() { 66 | let subscription = CKQuerySubscription(recordType: "Movie", 67 | predicate: NSPredicate(value: true), 68 | options: [.firesOnRecordCreation]) 69 | 70 | let info = CKNotificationInfo() 71 | info.alertLocalizationKey = "movie_registered_alert" 72 | info.alertLocalizationArgs = ["title"] 73 | info.soundName = "default" 74 | info.desiredKeys = ["title"] 75 | subscription.notificationInfo = info 76 | 77 | container.publicCloudDatabase.save(subscription) { [weak self] savedSubscription, error in 78 | DispatchQueue.main.async { 79 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 80 | self?.subscribeButton?.isEnabled = true 81 | 82 | guard let savedSubscription = savedSubscription, error == nil else { return } 83 | 84 | self?.isSubscribed = true 85 | 86 | UserDefaults.standard.set(savedSubscription.subscriptionID, forKey: "subscriptionID") 87 | } 88 | } 89 | } 90 | 91 | fileprivate func cancelSubscription() { 92 | guard let subscriptionID = subscriptionID else { return } 93 | 94 | subscribeButton.isEnabled = false 95 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 96 | 97 | let operation = CKModifySubscriptionsOperation(subscriptionsToSave: nil, subscriptionIDsToDelete: [subscriptionID]) 98 | 99 | operation.modifySubscriptionsCompletionBlock = { [weak self] _, _, error in 100 | DispatchQueue.main.async { 101 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 102 | self?.subscribeButton?.isEnabled = true 103 | 104 | guard error == nil else { return } 105 | 106 | self?.subscriptionID = nil 107 | self?.isSubscribed = false 108 | } 109 | } 110 | 111 | container.publicCloudDatabase.add(operation) 112 | } 113 | 114 | @IBAction func subscribe(_ sender: Any) { 115 | if isSubscribed { 116 | cancelSubscription() 117 | } else { 118 | createSubscription() 119 | } 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /CloudKitchenSink/UserViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UserViewController.swift 3 | // CloudKitchenSink 4 | // 5 | // Created by Guilherme Rambo on 05/03/17. 6 | // Copyright © 2017 Guilherme Rambo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CloudKit 11 | 12 | class UserViewController: UIViewController { 13 | 14 | @IBOutlet weak var idLabel: UILabel! 15 | @IBOutlet weak var nameLabel: UILabel! 16 | @IBOutlet weak var noAccountView: UIStackView! 17 | 18 | @IBOutlet weak var avatarSpinner: UIActivityIndicatorView! 19 | @IBOutlet weak var avatarContainerView: UIView! { 20 | didSet { 21 | avatarContainerView.clipsToBounds = true 22 | avatarContainerView.layer.cornerRadius = avatarContainerView.bounds.height / 2 23 | } 24 | } 25 | 26 | @IBOutlet weak var avatarImageView: UIImageView! 27 | 28 | var userRecord: CKRecord? { 29 | didSet { 30 | if let userRecord = userRecord { 31 | if let avatar = userRecord["avatar"] as? CKAsset { 32 | avatarImageView.image = UIImage(contentsOfFile: avatar.fileURL.path) 33 | } 34 | 35 | avatarContainerView.isHidden = false 36 | } else { 37 | avatarContainerView.isHidden = true 38 | } 39 | } 40 | } 41 | 42 | override func viewDidLoad() { 43 | super.viewDidLoad() 44 | 45 | NotificationCenter.default.addObserver(self, selector: #selector(startDiscoveryProcess), name: Notification.Name.CKAccountChanged, object: nil) 46 | 47 | startDiscoveryProcess() 48 | } 49 | 50 | @objc private func startDiscoveryProcess() { 51 | self.noAccountView.isHidden = true 52 | 53 | UIApplication.shared.isNetworkActivityIndicatorVisible = true 54 | 55 | container.accountStatus { status, error in 56 | DispatchQueue.main.async { 57 | if let error = error { 58 | let alert = UIAlertController(title: "Account Error", message: "Unable to determine iCloud account status.\n\(error.localizedDescription)", preferredStyle: .alert) 59 | self.present(alert, animated: true, completion: nil) 60 | 61 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 62 | } else { 63 | switch status { 64 | case .available: 65 | self.fetchUserRecordIdentifier() 66 | case .couldNotDetermine, .noAccount, .restricted: 67 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 68 | self.showNoAccountInfo() 69 | } 70 | } 71 | } 72 | } 73 | } 74 | 75 | private func showNoAccountInfo() { 76 | self.noAccountView.isHidden = false 77 | } 78 | 79 | @IBAction func logIn(_ sender: Any) { 80 | UIApplication.shared.open(URL(string: "App-Prefs:root=Settings")!, options: [:], completionHandler: nil) 81 | } 82 | 83 | private func fetchUserRecordIdentifier() { 84 | container.fetchUserRecordID { recordID, error in 85 | guard let recordID = recordID, error == nil else { 86 | // error handling magic 87 | return 88 | } 89 | 90 | DispatchQueue.main.async { 91 | self.idLabel.text = recordID.recordName 92 | 93 | print("Got user record ID \(recordID.recordName). Fetching info...") 94 | 95 | self.fetchUserRecord(with: recordID) 96 | self.discoverIdentity(for: recordID) 97 | self.discoverFriends() 98 | } 99 | } 100 | } 101 | 102 | private func fetchUserRecord(with recordID: CKRecordID) { 103 | container.publicCloudDatabase.fetch(withRecordID: recordID) { record, error in 104 | guard let record = record, error == nil else { 105 | // show off your error handling skills 106 | return 107 | } 108 | 109 | print("The user record is: \(record)") 110 | 111 | DispatchQueue.main.async { 112 | self.userRecord = record 113 | } 114 | } 115 | } 116 | 117 | private func discoverIdentity(for recordID: CKRecordID) { 118 | container.requestApplicationPermission(.userDiscoverability) { status, error in 119 | guard status == .granted, error == nil else { 120 | // error handling voodoo 121 | DispatchQueue.main.async { 122 | self.nameLabel.text = "NOT AUTHORIZED" 123 | } 124 | return 125 | } 126 | 127 | self.container.discoverUserIdentity(withUserRecordID: recordID) { identity, error in 128 | defer { 129 | DispatchQueue.main.async { 130 | UIApplication.shared.isNetworkActivityIndicatorVisible = false 131 | } 132 | } 133 | 134 | guard let components = identity?.nameComponents, error == nil else { 135 | // more error handling magic 136 | return 137 | } 138 | 139 | DispatchQueue.main.async { 140 | let formatter = PersonNameComponentsFormatter() 141 | self.nameLabel.text = formatter.string(from: components) 142 | } 143 | } 144 | } 145 | } 146 | 147 | private func discoverFriends() { 148 | container.discoverAllIdentities { identities, error in 149 | guard let identities = identities, error == nil else { 150 | // awesome error handling 151 | return 152 | } 153 | 154 | print("User has \(identities.count) contact(s) using the app:") 155 | print("\(identities)") 156 | } 157 | } 158 | 159 | @IBAction func changeAvatar(_ sender: Any) { 160 | let imagePicker = UIImagePickerController() 161 | imagePicker.sourceType = .photoLibrary 162 | imagePicker.delegate = self 163 | present(imagePicker, animated: true, completion: nil) 164 | } 165 | 166 | } 167 | 168 | 169 | extension UserViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { 170 | 171 | func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 172 | defer { 173 | picker.dismiss(animated: true, completion: nil) 174 | } 175 | 176 | guard let userRecord = userRecord, 177 | let image = info[UIImagePickerControllerOriginalImage] as? UIImage, 178 | let imageData = UIImagePNGRepresentation(image) 179 | else { 180 | print("Missing some data, unable to set the avatar now") 181 | return 182 | } 183 | 184 | let previousImage = avatarImageView.image 185 | avatarImageView.image = image 186 | 187 | do { 188 | let path = NSTemporaryDirectory() + "avatar_temp_\(UUID().uuidString).png" 189 | let url = URL(fileURLWithPath: path) 190 | 191 | try imageData.write(to: url) 192 | 193 | updateUserRecord(userRecord, with: url, fallbackImage: previousImage) 194 | } catch { 195 | print("Error writing avatar to temporary directory: \(error)") 196 | } 197 | } 198 | 199 | private func updateUserRecord(_ userRecord: CKRecord, with avatarURL: URL, fallbackImage: UIImage?) { 200 | avatarSpinner.startAnimating() 201 | avatarImageView.alpha = 0.5 202 | 203 | userRecord["avatar"] = CKAsset(fileURL: avatarURL) 204 | 205 | container.publicCloudDatabase.save(userRecord) { _, error in 206 | defer { 207 | DispatchQueue.main.async { 208 | self.avatarImageView.alpha = 1 209 | self.avatarSpinner.stopAnimating() 210 | 211 | do { 212 | try FileManager.default.removeItem(at: avatarURL) 213 | } catch { 214 | print("Error deleting temporary avatar file: \(error)") 215 | } 216 | } 217 | } 218 | 219 | guard error == nil else { 220 | // top-notch error handling 221 | DispatchQueue.main.async { 222 | self.avatarImageView.image = fallbackImage 223 | } 224 | return 225 | } 226 | 227 | print("Successfully updated user record with new avatar") 228 | } 229 | } 230 | 231 | } 232 | -------------------------------------------------------------------------------- /CloudKitchenSink/pt-BR.lproj/LaunchScreen.strings: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /CloudKitchenSink/pt-BR.lproj/Main.strings: -------------------------------------------------------------------------------- 1 | 2 | /* Class = "UILabel"; text = "Release date:"; ObjectID = "0Ua-oV-lTu"; */ 3 | "0Ua-oV-lTu.text" = "Release date:"; 4 | 5 | /* Class = "UINavigationItem"; title = "Simple Record"; ObjectID = "2eG-Lp-nf8"; */ 6 | "2eG-Lp-nf8.title" = "Simple Record"; 7 | 8 | /* Class = "UILabel"; text = "Title:"; ObjectID = "2px-0w-2zF"; */ 9 | "2px-0w-2zF.text" = "Title:"; 10 | 11 | /* Class = "UIButton"; normalTitle = "Save"; ObjectID = "3lr-CX-PYg"; */ 12 | "3lr-CX-PYg.normalTitle" = "Save"; 13 | 14 | /* Class = "UILabel"; text = "iCloud account not found"; ObjectID = "6l1-Rm-Ujd"; */ 15 | "6l1-Rm-Ujd.text" = "iCloud account not found"; 16 | 17 | /* Class = "UILabel"; text = "All Records"; ObjectID = "7Fs-A4-Uhd"; */ 18 | "7Fs-A4-Uhd.text" = "All Records"; 19 | 20 | /* Class = "UIButton"; normalTitle = "Subscribe"; ObjectID = "7GY-GS-lla"; */ 21 | "7GY-GS-lla.normalTitle" = "Subscribe"; 22 | 23 | /* Class = "UITextField"; placeholder = "Movie Title"; ObjectID = "CHe-k3-Qb8"; */ 24 | "CHe-k3-Qb8.placeholder" = "Movie Title"; 25 | 26 | /* Class = "UITabBarItem"; title = "Notifications"; ObjectID = "Czx-Ng-hvT"; */ 27 | "Czx-Ng-hvT.title" = "Notifications"; 28 | 29 | /* Class = "UILabel"; text = "Subtitle"; ObjectID = "J1I-pK-ISz"; */ 30 | "J1I-pK-ISz.text" = "Subtitle"; 31 | 32 | /* Class = "UILabel"; text = "Name:"; ObjectID = "Lcp-Vc-Dhe"; */ 33 | "Lcp-Vc-Dhe.text" = "Name:"; 34 | 35 | /* Class = "UITabBarItem"; title = "Query"; ObjectID = "PO1-0f-FGR"; */ 36 | "PO1-0f-FGR.title" = "Query"; 37 | 38 | /* Class = "UILabel"; text = "Rating:"; ObjectID = "Qy0-09-cXf"; */ 39 | "Qy0-09-cXf.text" = "Rating:"; 40 | 41 | /* Class = "UILabel"; text = "(not set)"; ObjectID = "ShP-ER-qMT"; */ 42 | "ShP-ER-qMT.text" = "(not set)"; 43 | 44 | /* Class = "UIButton"; normalTitle = "Search"; ObjectID = "Tnm-rB-gcz"; */ 45 | "Tnm-rB-gcz.normalTitle" = "Search"; 46 | 47 | /* Class = "UILabel"; text = "Search by location"; ObjectID = "WJf-oQ-szP"; */ 48 | "WJf-oQ-szP.text" = "Search by location"; 49 | 50 | /* Class = "UIButton"; normalTitle = "Log In"; ObjectID = "YsL-EK-h0z"; */ 51 | "YsL-EK-h0z.normalTitle" = "Log In"; 52 | 53 | /* Class = "UILabel"; text = "Title"; ObjectID = "ak7-zU-eJU"; */ 54 | "ak7-zU-eJU.text" = "Title"; 55 | 56 | /* Class = "UITextField"; placeholder = "ex: New York"; ObjectID = "bfw-x1-MRW"; */ 57 | "bfw-x1-MRW.placeholder" = "ex: New York"; 58 | 59 | /* Class = "UINavigationItem"; title = "Query"; ObjectID = "eDH-1l-cHl"; */ 60 | "eDH-1l-cHl.title" = "Query"; 61 | 62 | /* Class = "UITabBarItem"; title = "Record"; ObjectID = "fRU-rx-tDp"; */ 63 | "fRU-rx-tDp.title" = "Record"; 64 | 65 | /* Class = "UILabel"; text = "User ID:"; ObjectID = "frr-dj-YCu"; */ 66 | "frr-dj-YCu.text" = "User ID:"; 67 | 68 | /* Class = "UILabel"; text = "Be notified when new movies are registered"; ObjectID = "kX4-mp-mc6"; */ 69 | "kX4-mp-mc6.text" = "Be notified when new movies are registered"; 70 | 71 | /* Class = "UINavigationItem"; title = "Notifications"; ObjectID = "kgt-ya-eYu"; */ 72 | "kgt-ya-eYu.title" = "Notifications"; 73 | 74 | /* Class = "UILabel"; text = "(not set)"; ObjectID = "lvb-Sp-0Nq"; */ 75 | "lvb-Sp-0Nq.text" = "(not set)"; 76 | 77 | /* Class = "UITabBarItem"; title = "User"; ObjectID = "m3e-1S-vup"; */ 78 | "m3e-1S-vup.title" = "User"; 79 | 80 | /* Class = "UIButton"; normalTitle = "Edit"; ObjectID = "nNM-pS-fNd"; */ 81 | "nNM-pS-fNd.normalTitle" = "Edit"; 82 | 83 | /* Class = "UILabel"; text = "Location:"; ObjectID = "omC-Eb-han"; */ 84 | "omC-Eb-han.text" = "Location:"; 85 | 86 | /* Class = "UITextField"; placeholder = "YYYY-MM-DD"; ObjectID = "p1x-jW-F2A"; */ 87 | "p1x-jW-F2A.placeholder" = "YYYY-MM-DD"; 88 | 89 | /* Class = "UILabel"; text = "Search by title"; ObjectID = "rTR-dC-9Bg"; */ 90 | "rTR-dC-9Bg.text" = "Search by title"; 91 | 92 | /* Class = "UINavigationItem"; title = "iCloud User"; ObjectID = "u5Q-wu-pWY"; */ 93 | "u5Q-wu-pWY.title" = "iCloud User"; 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Peixe Urbano 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CloudKitchenSink 2 | 3 | ## English 4 | 5 | A collection of CloudKit code samples written for my article on CloudKit. 6 | 7 | To build and run the project you'll need a developer account with apple and a CloudKit container configured for the app. 8 | 9 | ## Português 10 | 11 | Uma coleção de exemplos de código sobre CloudKit. Este projeto acompanha meu artigo do equinociOS 2017. 12 | 13 | Para rodar o projeto você precisará de uma conta de desenvolvedor com a Apple e precisará configurar um container no CloudKit. --------------------------------------------------------------------------------