Skip to content

Commit 9b7a960

Browse files
authored
fix: SDK does not properly wait for initialization (#168)
* fix: SDK does not properly wait for initialization * add a change log entry * lint
1 parent 702ca34 commit 9b7a960

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.9.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

88

9+
### 5.9.3
10+
[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)
11+
12+
__Fixes__
13+
* 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).
14+
915
### 5.9.2
1016
[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)
1117

Sources/ParseSwift/Authentication/Protocols/ParseAuthentication.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ public extension ParseUser {
420420
}
421421

422422
internal func linkCommand(body: SignupLoginBody) async throws -> API.Command<SignupLoginBody, Self> {
423+
try await yieldIfNotInitialized()
423424
let currentStrippedUser = try await self.anonymous.strip()
424425
var body = body
425426
if var currentAuthData = currentStrippedUser.authData {

Sources/ParseSwift/Objects/ParseInstallation.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,25 @@ public extension ParseInstallation {
12301230
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
12311231
desires a different policy, it should be inserted in `options`.
12321232
*/
1233-
static func deleteObjCKeychain(options: API.Options = [],
1234-
callbackQueue: DispatchQueue = .main,
1235-
completion: @escaping (Result<Void, ParseError>) -> Void) {
1233+
static func deleteObjCKeychain( // swiftlint:disable:this function_body_length
1234+
options: API.Options = [],
1235+
callbackQueue: DispatchQueue = .main,
1236+
completion: @escaping (Result<Void, ParseError>) -> Void
1237+
) {
12361238
Task {
1239+
do {
1240+
try await yieldIfNotInitialized()
1241+
} catch {
1242+
let defaultError = ParseError(
1243+
code: .otherCause,
1244+
swift: error
1245+
)
1246+
let parseError = error as? ParseError ?? defaultError
1247+
callbackQueue.async {
1248+
completion(.failure(parseError))
1249+
}
1250+
return
1251+
}
12371252
guard let objcParseKeychain = KeychainStore.objectiveC,
12381253
// swiftlint:disable:next line_length
12391254
let oldInstallationId: String = await objcParseKeychain.objectObjectiveC(forKey: "installationId") else {

Sources/ParseSwift/Objects/ParseUser.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public extension ParseUser {
186186
}
187187

188188
internal static func setCurrent(_ newValue: Self?) async throws {
189+
try await yieldIfNotInitialized()
189190
var currentContainer = await Self.currentContainer()
190191
if let newValue = newValue,
191192
let currentUser = currentContainer?.currentUser {
@@ -438,6 +439,19 @@ extension ParseUser {
438439
callbackQueue: DispatchQueue = .main,
439440
completion: @escaping (Result<Self, ParseError>) -> Void) {
440441
Task {
442+
do {
443+
try await yieldIfNotInitialized()
444+
} catch {
445+
let defaultError = ParseError(
446+
code: .otherCause,
447+
swift: error
448+
)
449+
let parseError = error as? ParseError ?? defaultError
450+
callbackQueue.async {
451+
completion(.failure(parseError))
452+
}
453+
return
454+
}
441455
let objcParseKeychain = KeychainStore.objectiveC
442456
// swiftlint:disable:next line_length
443457
guard let objcParseUser: [String: String] = await objcParseKeychain?.objectObjectiveC(forKey: "currentUser"),

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.9.2"
13+
static let version = "5.9.3"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

0 commit comments

Comments
 (0)