Skip to content
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
38 changes: 21 additions & 17 deletions swift/Tasks.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4170A8552CED346F00043F5A /* DittoObjC in Frameworks */ = {isa = PBXBuildFile; productRef = 4170A8542CED346F00043F5A /* DittoObjC */; };
4170A8572CED346F00043F5A /* DittoSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 4170A8562CED346F00043F5A /* DittoSwift */; };
0D40BBA72F2AAE8A006A72A4 /* DittoSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 0D40BBA62F2AAE8A006A72A4 /* DittoSwift */; };
ABCDEF012345678900000001 /* TasksUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABCDEF012345678900000002 /* TasksUITests.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -55,8 +54,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4170A8552CED346F00043F5A /* DittoObjC in Frameworks */,
4170A8572CED346F00043F5A /* DittoSwift in Frameworks */,
0D40BBA72F2AAE8A006A72A4 /* DittoSwift in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -70,11 +68,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0D40BBA52F2AAE8A006A72A4 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
41F869812CECF42500DC7268 = {
isa = PBXGroup;
children = (
41F8698C2CECF42500DC7268 /* Tasks */,
ABCDEF012345678900000005 /* TasksUITests */,
0D40BBA52F2AAE8A006A72A4 /* Frameworks */,
41F8698B2CECF42500DC7268 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -118,8 +124,7 @@
);
name = Tasks;
packageProductDependencies = (
4170A8542CED346F00043F5A /* DittoObjC */,
4170A8562CED346F00043F5A /* DittoSwift */,
0D40BBA62F2AAE8A006A72A4 /* DittoSwift */,
);
productName = Tasks;
productReference = 41F8698A2CECF42500DC7268 /* Tasks.app */;
Expand Down Expand Up @@ -151,7 +156,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1610;
LastUpgradeCheck = 1610;
LastUpgradeCheck = 2620;
TargetAttributes = {
41F869892CECF42500DC7268 = {
CreatedOnToolsVersion = 16.1;
Expand All @@ -168,7 +173,7 @@
mainGroup = 41F869812CECF42500DC7268;
minimizedProjectReferenceProxies = 1;
packageReferences = (
4170A8532CED346F00043F5A /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */,
0D40BBA42F2AAE7D006A72A4 /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 41F8698B2CECF42500DC7268 /* Products */;
Expand Down Expand Up @@ -326,6 +331,7 @@
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -382,6 +388,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_COMPILATION_MODE = wholemodule;
VALIDATE_PRODUCT = YES;
};
Expand All @@ -400,6 +407,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Tasks/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Ditto Tasks";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Uses Bluetooth to connect and sync with nearby devices";
INFOPLIST_KEY_NSBluetoothPeripheralUsageDescription = "Uses Bluetooth to connect and sync with nearby devices";
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Uses WiFi to connect and sync with nearby devices";
Expand Down Expand Up @@ -435,6 +443,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Tasks/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Ditto Tasks";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Uses Bluetooth to connect and sync with nearby devices";
INFOPLIST_KEY_NSBluetoothPeripheralUsageDescription = "Uses Bluetooth to connect and sync with nearby devices";
INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Uses WiFi to connect and sync with nearby devices";
Expand Down Expand Up @@ -526,25 +535,20 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
4170A8532CED346F00043F5A /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */ = {
0D40BBA42F2AAE7D006A72A4 /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/getditto/DittoSwiftPackage";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.13.1;
minimumVersion = "5.0.0-dev-weekly.20260126.180";
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
4170A8542CED346F00043F5A /* DittoObjC */ = {
isa = XCSwiftPackageProductDependency;
package = 4170A8532CED346F00043F5A /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */;
productName = DittoObjC;
};
4170A8562CED346F00043F5A /* DittoSwift */ = {
0D40BBA62F2AAE8A006A72A4 /* DittoSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 4170A8532CED346F00043F5A /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */;
package = 0D40BBA42F2AAE7D006A72A4 /* XCRemoteSwiftPackageReference "DittoSwiftPackage" */;
productName = DittoSwift;
};
/* End XCSwiftPackageProductDependency section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1640"
LastUpgradeVersion = "2620"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
55 changes: 30 additions & 25 deletions swift/Tasks/DittoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@ import Foundation

/// Owner of the Ditto object
class DittoManager: ObservableObject {
let ditto: Ditto
@Published var ditto: Ditto?
static let shared = DittoManager()

private init() {
// https://docs.ditto.live/sdk/latest/install-guides/swift#integrating-and-initializing-sync
ditto = Ditto(
identity: .onlinePlayground(
appID: Env.DITTO_APP_ID,
token: Env.DITTO_PLAYGROUND_TOKEN,
// This is required to be set to false to use the correct URLs
// This only disables cloud sync when the webSocketURL is not set explicitly
enableDittoCloudSync: false,
customAuthURL: URL(string: Env.DITTO_AUTH_URL)
)
)
private init() {}

// Set the Ditto Websocket URL
ditto.updateTransportConfig { transportConfig in
transportConfig.connect.webSocketURLs.insert(Env.DITTO_WEBSOCKET_URL)
}
/// Initializes Ditto and configures logging. Handles thrown errors.
func initDitto() async throws {
// https://docs.ditto.live/sdk/latest/ditto-config
let config = DittoConfig(
databaseID: Env.DITTO_APP_ID,
connect: .server(url: URL(string: Env.DITTO_AUTH_URL)!))

// disable sync with v3 peers, required for DQL
do {
try ditto.disableSyncWithV3()
} catch let error {
print(
"DittoManger - ERROR: disableSyncWithV3() failed with error \"\(error)\""
)
let dittoOpened = try await Ditto.open(config: config)
dittoOpened.auth?.expirationHandler = { ditto, secondsRemaining in
// Authenticate when token is expiring. This closure must not throw.
ditto.auth?.login(token: Env.DITTO_PLAYGROUND_TOKEN,
provider: .development) { clientInfo, error in
if let error = error {
// Cannot throw from here; log the error instead.
print(
"Ditto auth refresh failed: \(error), " +
"client info: \(String(describing: clientInfo)), " +
"seconds remaining \(secondsRemaining)"
)
}
}
}
self.ditto = dittoOpened

} catch {
self.ditto = nil
throw error
}

let isPreview: Bool =
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
// Configure logging for non-preview runs
let isPreview: Bool = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
if !isPreview {
DittoLogger.minimumLogLevel = .debug
}
Expand Down
9 changes: 2 additions & 7 deletions swift/Tasks/TasksApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import SwiftUI
@main
struct TasksApp: App {
@State private var isLoading = true
private let ditto = DittoManager.shared.ditto

var body: some Scene {
WindowGroup {
Expand All @@ -16,14 +15,10 @@ struct TasksApp: App {
}
.task {
do {
// Disable DQL strict mode. When set to false, collection
// definitions are no longer required. SELECT queries will
// return and display all fields by default.
// https://docs.ditto.live/dql/strict-mode
try await ditto.store.execute(query: "ALTER SYSTEM SET DQL_STRICT_MODE = false")
try await DittoManager.shared.initDitto()
isLoading = false
} catch {
fatalError("Internal inconsistency, expected setting DQL strict mode to false to always succeed but it failed: \(error)")
fatalError("Failed to initialize Ditto: \(error)")
}
}
}
Expand Down
Loading
Loading