Skip to content

Commit e4d22f7

Browse files
authored
fix: Handle pointer on Installation and User creation (#196)
* fix: Handle pointer on Installation and User creation * add changelog and bump version
1 parent 7a06604 commit e4d22f7

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

CHANGELOG.md

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

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.12.0...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.12.1...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

8+
### 5.12.1
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.12.0...5.12.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.12.1/documentation/parseswift)
10+
11+
__Fixes__
12+
* Fix failing to decode a ParseInstallation or ParseUser due to object returning from the server as a pointer ([#196](https://github.com/netreconlab/Parse-Swift/pull/196)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.12.0
915
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.5...5.12.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.12.0/documentation/parseswift)
1016

Sources/ParseSwift/API/ParseURLSessionDelegate.swift

Lines changed: 1 addition & 1 deletion
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

Lines changed: 21 additions & 1 deletion
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

Lines changed: 21 additions & 6 deletions
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>(

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.12.0"
13+
static let version = "5.12.1"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Tests/ParseSwiftTests/APICommandMultipleAttemptsTests.swift

Lines changed: 1 addition & 1 deletion
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)