From f5b032bda9223e2db932cdbd5af3c0edddb81811 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Fri, 29 Mar 2024 16:35:58 -0700 Subject: [PATCH 1/3] fix: SDK does not properly wait for initialization --- .../Protocols/ParseAuthentication.swift | 1 + Sources/ParseSwift/Objects/ParseInstallation.swift | 13 +++++++++++++ Sources/ParseSwift/Objects/ParseUser.swift | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Sources/ParseSwift/Authentication/Protocols/ParseAuthentication.swift b/Sources/ParseSwift/Authentication/Protocols/ParseAuthentication.swift index 1d49181ec..698a3ad0f 100644 --- a/Sources/ParseSwift/Authentication/Protocols/ParseAuthentication.swift +++ b/Sources/ParseSwift/Authentication/Protocols/ParseAuthentication.swift @@ -420,6 +420,7 @@ public extension ParseUser { } internal func linkCommand(body: SignupLoginBody) async throws -> API.Command { + try await yieldIfNotInitialized() let currentStrippedUser = try await self.anonymous.strip() var body = body if var currentAuthData = currentStrippedUser.authData { diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index 00a95cd43..50eaf42eb 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -1234,6 +1234,19 @@ public extension ParseInstallation { callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void) { Task { + do { + try await yieldIfNotInitialized() + } catch { + let defaultError = ParseError( + code: .otherCause, + swift: error + ) + let parseError = error as? ParseError ?? defaultError + callbackQueue.async { + completion(.failure(parseError)) + } + return + } guard let objcParseKeychain = KeychainStore.objectiveC, // swiftlint:disable:next line_length let oldInstallationId: String = await objcParseKeychain.objectObjectiveC(forKey: "installationId") else { diff --git a/Sources/ParseSwift/Objects/ParseUser.swift b/Sources/ParseSwift/Objects/ParseUser.swift index 36588f118..882341fcd 100644 --- a/Sources/ParseSwift/Objects/ParseUser.swift +++ b/Sources/ParseSwift/Objects/ParseUser.swift @@ -186,6 +186,7 @@ public extension ParseUser { } internal static func setCurrent(_ newValue: Self?) async throws { + try await yieldIfNotInitialized() var currentContainer = await Self.currentContainer() if let newValue = newValue, let currentUser = currentContainer?.currentUser { @@ -438,6 +439,19 @@ extension ParseUser { callbackQueue: DispatchQueue = .main, completion: @escaping (Result) -> Void) { Task { + do { + try await yieldIfNotInitialized() + } catch { + let defaultError = ParseError( + code: .otherCause, + swift: error + ) + let parseError = error as? ParseError ?? defaultError + callbackQueue.async { + completion(.failure(parseError)) + } + return + } let objcParseKeychain = KeychainStore.objectiveC // swiftlint:disable:next line_length guard let objcParseUser: [String: String] = await objcParseKeychain?.objectObjectiveC(forKey: "currentUser"), From 41ddbfceeca5a72b2b7f250f0f3c3daced4f14a6 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Fri, 29 Mar 2024 16:40:03 -0700 Subject: [PATCH 2/3] add a change log entry --- CHANGELOG.md | 8 +++++++- Sources/ParseSwift/ParseConstants.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4fbf3faf..299cdc265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,16 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift) +[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 5.9.3 +[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.2...5.9.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.9.3/documentation/parseswift) + +__Fixes__ +* Certain calls to the user or installation did not wait for the SDK to initialize causing a crash ([#163](https://github.com/netreconlab/Parse-Swift/pull/163)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 5.9.2 [Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.1...5.9.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.9.2/documentation/parseswift) diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 608421dd7..151ecf411 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "5.9.2" + static let version = "5.9.3" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" static let fileManagementLibraryDirectory = "Library/" From 0dc105efede7a8f19994291706f7af6f59c2f978 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Fri, 29 Mar 2024 17:00:43 -0700 Subject: [PATCH 3/3] lint --- Sources/ParseSwift/Objects/ParseInstallation.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/ParseSwift/Objects/ParseInstallation.swift b/Sources/ParseSwift/Objects/ParseInstallation.swift index 50eaf42eb..25a71f4cd 100644 --- a/Sources/ParseSwift/Objects/ParseInstallation.swift +++ b/Sources/ParseSwift/Objects/ParseInstallation.swift @@ -1230,9 +1230,11 @@ public extension ParseInstallation { - note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer desires a different policy, it should be inserted in `options`. */ - static func deleteObjCKeychain(options: API.Options = [], - callbackQueue: DispatchQueue = .main, - completion: @escaping (Result) -> Void) { + static func deleteObjCKeychain( // swiftlint:disable:this function_body_length + options: API.Options = [], + callbackQueue: DispatchQueue = .main, + completion: @escaping (Result) -> Void + ) { Task { do { try await yieldIfNotInitialized()