Skip to content

Commit 5bbe702

Browse files
committed
fix: Handle pointer on Installation and User creation
1 parent 7a06604 commit 5bbe702

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

Sources/ParseSwift/API/ParseURLSessionDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ParseURLSessionDelegate: NSObject {
1818
URLCredential?) -> Void) -> Void)?
1919
var streamDelegates = [URLSessionTask: InputStream]()
2020

21-
actor SessionDelegate: Sendable {
21+
actor SessionDelegate {
2222
var downloadDelegates = [URLSessionDownloadTask: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)]()
2323
var uploadDelegates = [URLSessionTask: ((URLSessionTask, Int64, Int64, Int64) -> Void)]()
2424
var taskCallbackQueues = [URLSessionTask: DispatchQueue]()

Sources/ParseSwift/Objects/ParseInstallation.swift

+21-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,27 @@ extension ParseInstallation {
749749
}
750750
let updatedObject = object
751751
let mapper = { @Sendable (data) -> Self in
752-
try ParseCoding.jsonDecoder().decode(CreateResponse.self, from: data).apply(to: updatedObject)
752+
do {
753+
// Try to decode CreateResponse, if that doesn't work try Pointer
754+
let savedObject = try ParseCoding.jsonDecoder().decode(
755+
CreateResponse.self,
756+
from: data
757+
).apply(to: updatedObject)
758+
759+
return savedObject
760+
} catch let originalError {
761+
do {
762+
let pointer = try ParseCoding.jsonDecoder().decode(
763+
Pointer<Self>.self,
764+
from: data
765+
)
766+
var objectToUpdate = updatedObject
767+
objectToUpdate.objectId = pointer.objectId
768+
return objectToUpdate
769+
} catch {
770+
throw originalError
771+
}
772+
}
753773
}
754774
return API.Command<Self, Self>(method: .POST,
755775
path: try await endpoint(.POST),

Sources/ParseSwift/Objects/ParseUser.swift

+21-6
Original file line numberDiff line numberDiff line change
@@ -1218,12 +1218,27 @@ extension ParseUser {
12181218
}
12191219
let updatedUser = user
12201220
let mapper = { @Sendable (data) -> Self in
1221-
try ParseCoding
1222-
.jsonDecoder()
1223-
.decode(
1224-
CreateResponse.self,
1225-
from: data
1226-
).apply(to: updatedUser)
1221+
do {
1222+
// Try to decode CreateResponse, if that doesn't work try Pointer
1223+
let savedObject = try ParseCoding.jsonDecoder().decode(
1224+
CreateResponse.self,
1225+
from: data
1226+
).apply(to: updatedUser)
1227+
1228+
return savedObject
1229+
} catch let originalError {
1230+
do {
1231+
let pointer = try ParseCoding.jsonDecoder().decode(
1232+
Pointer<Self>.self,
1233+
from: data
1234+
)
1235+
var objectToUpdate = updatedUser
1236+
objectToUpdate.objectId = pointer.objectId
1237+
return objectToUpdate
1238+
} catch {
1239+
throw originalError
1240+
}
1241+
}
12271242
}
12281243
let path = try await endpoint(.POST)
12291244
let command = API.Command<Self, Self>(

Tests/ParseSwiftTests/APICommandMultipleAttemptsTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class APICommandMultipleAttemptsTests: XCTestCase {
5757
try await ParseStorage.shared.deleteAll()
5858
}
5959

60-
actor Result: Sendable {
60+
actor Result {
6161
var attempts = 0
6262

6363
func incrementAttempts() {

0 commit comments

Comments
 (0)