Skip to content

Commit

Permalink
Make sure disabling iCloud store works
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatch committed Sep 15, 2022
1 parent 70177e8 commit 4924d92
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions Oak/Injected/Utils+Injection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Resolver

extension Resolver {
static func RegisterAllUtils() {
RegisterBuildConfigurationUtil()
RegisterSettingsUtil()
RegisterICloudSettingsUtil()
RegisterHapticsUtil()
Expand Down
3 changes: 2 additions & 1 deletion Oak/Persistence/PersistentStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protocol PersistentStore {
class RealPersistentStore: PersistentStore {
private var persistentContainer: NSPersistentContainer!
@Injected private var iCloudSettings: ICloudSettings
@Injected private var buildConfiguration: BuildConfiguration

var viewContext: NSManagedObjectContext {
return persistentContainer.viewContext
Expand Down Expand Up @@ -69,7 +70,7 @@ class RealPersistentStore: PersistentStore {
}

public func deleteUserAccounts() {
let container = CKContainer.default()
let container = CKContainer(identifier: buildConfiguration.ICloudContainerName)
let database = container.privateCloudDatabase

database.delete(withRecordZoneID: .init(zoneName: "com.apple.coredata.cloudkit.zone"), completionHandler: { (zoneID, error) in
Expand Down
41 changes: 41 additions & 0 deletions Oak/Util/BuildConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// BuildEnvironment.swift
// OakOTP
//
// Created by Alex Catchpole on 15/09/2022.
//

import Foundation
import Resolver

enum BuildEnvironment: String { // 1
case debugDevelopment = "Debug Development"
case debugProduction = "Debug Production"

case releaseProduction = "Release Production"
case releaseDevelopment = "Release Development"
}

class BuildConfiguration { // 2
var environment: BuildEnvironment

var ICloudContainerName: String {
switch environment {
case .debugProduction, .debugDevelopment:
return "iCloud.sh.catch.oakdebug.icloud"
case .releaseDevelopment, .releaseProduction:
return "iCloud.sh.catch.oak.icloud"
}
}

init() {
let currentConfiguration = Bundle.main.object(forInfoDictionaryKey: "Configuration") as! String
environment = BuildEnvironment(rawValue: currentConfiguration)!
}
}

extension Resolver {
static func RegisterBuildConfigurationUtil() {
register { BuildConfiguration() }.scope(.application)
}
}
8 changes: 7 additions & 1 deletion OakOTP.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
09CFCECA26504079001954C5 /* ICloudSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CFCEC926504079001954C5 /* ICloudSettings.swift */; };
09CFCECC26504197001954C5 /* ICloudToggableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CFCECB26504197001954C5 /* ICloudToggableRow.swift */; };
09CFCECF26516905001954C5 /* SwiftlySearch in Frameworks */ = {isa = PBXBuildFile; productRef = 09CFCECE26516905001954C5 /* SwiftlySearch */; };
09F00B4528D389AD000C0D6B /* BuildConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09F00B4428D389AC000C0D6B /* BuildConfiguration.swift */; };
FA03411025C9BF7F004752F3 /* AuthenticationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA03410F25C9BF7F004752F3 /* AuthenticationViewModel.swift */; };
FA03411725C9C640004752F3 /* Resolver in Frameworks */ = {isa = PBXBuildFile; productRef = FA03411625C9C640004752F3 /* Resolver */; };
FA03411C25C9C7BE004752F3 /* Services+Injection.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA03411B25C9C7BE004752F3 /* Services+Injection.swift */; };
Expand Down Expand Up @@ -151,6 +152,7 @@
09CFCEC72650247B001954C5 /* IsHiddenModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsHiddenModifier.swift; sourceTree = "<group>"; };
09CFCEC926504079001954C5 /* ICloudSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICloudSettings.swift; sourceTree = "<group>"; };
09CFCECB26504197001954C5 /* ICloudToggableRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICloudToggableRow.swift; sourceTree = "<group>"; };
09F00B4428D389AC000C0D6B /* BuildConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildConfiguration.swift; sourceTree = "<group>"; };
FA03410F25C9BF7F004752F3 /* AuthenticationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationViewModel.swift; sourceTree = "<group>"; };
FA03411B25C9C7BE004752F3 /* Services+Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Services+Injection.swift"; sourceTree = "<group>"; };
FA03412625C9C8D0004752F3 /* Injection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Injection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -549,6 +551,7 @@
FAB8CB2D25C8FF93001DE486 /* Biometrics.swift */,
092A677B25CC605A00E8118E /* Window.swift */,
09CFCEC926504079001954C5 /* ICloudSettings.swift */,
09F00B4428D389AC000C0D6B /* BuildConfiguration.swift */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -633,7 +636,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1230;
LastUpgradeCheck = 1400;
TargetAttributes = {
099EC37D265546FA00CA5F86 = {
CreatedOnToolsVersion = 12.5;
Expand Down Expand Up @@ -768,6 +771,7 @@
FADAE48E25C9E9FD005BC18E /* SetupView.swift in Sources */,
FA0B7ACD25C8BD7800D8A48B /* SettingsViewModel.swift in Sources */,
FACB8CF025C9F48600688223 /* MainViewModel.swift in Sources */,
09F00B4528D389AD000C0D6B /* BuildConfiguration.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1213,6 +1217,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -1224,6 +1229,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 14.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
Expand Down
1 change: 1 addition & 0 deletions OakOTP.xcodeproj/xcshareddata/xcschemes/OakDebug.xcscheme
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion OakOTP.xcodeproj/xcshareddata/xcschemes/OakTests.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 4924d92

Please sign in to comment.