Skip to content

fix: Handle pointer on Installation and User creation #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# Parse-Swift Changelog

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

__Fixes__
* 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).

### 5.12.0
[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)

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/ParseURLSessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ParseURLSessionDelegate: NSObject {
URLCredential?) -> Void) -> Void)?
var streamDelegates = [URLSessionTask: InputStream]()

actor SessionDelegate: Sendable {
actor SessionDelegate {
var downloadDelegates = [URLSessionDownloadTask: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)]()
var uploadDelegates = [URLSessionTask: ((URLSessionTask, Int64, Int64, Int64) -> Void)]()
var taskCallbackQueues = [URLSessionTask: DispatchQueue]()
Expand Down
22 changes: 21 additions & 1 deletion Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,27 @@ extension ParseInstallation {
}
let updatedObject = object
let mapper = { @Sendable (data) -> Self in
try ParseCoding.jsonDecoder().decode(CreateResponse.self, from: data).apply(to: updatedObject)
do {
// Try to decode CreateResponse, if that doesn't work try Pointer
let savedObject = try ParseCoding.jsonDecoder().decode(
CreateResponse.self,
from: data
).apply(to: updatedObject)

return savedObject
} catch let originalError {
do {
let pointer = try ParseCoding.jsonDecoder().decode(
Pointer<Self>.self,
from: data
)
var objectToUpdate = updatedObject
objectToUpdate.objectId = pointer.objectId
return objectToUpdate
} catch {
throw originalError
}
}
}
return API.Command<Self, Self>(method: .POST,
path: try await endpoint(.POST),
Expand Down
27 changes: 21 additions & 6 deletions Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1218,12 +1218,27 @@ extension ParseUser {
}
let updatedUser = user
let mapper = { @Sendable (data) -> Self in
try ParseCoding
.jsonDecoder()
.decode(
CreateResponse.self,
from: data
).apply(to: updatedUser)
do {
// Try to decode CreateResponse, if that doesn't work try Pointer
let savedObject = try ParseCoding.jsonDecoder().decode(
CreateResponse.self,
from: data
).apply(to: updatedUser)

return savedObject
} catch let originalError {
do {
let pointer = try ParseCoding.jsonDecoder().decode(
Pointer<Self>.self,
from: data
)
var objectToUpdate = updatedUser
objectToUpdate.objectId = pointer.objectId
return objectToUpdate
} catch {
throw originalError
}
}
}
let path = try await endpoint(.POST)
let command = API.Command<Self, Self>(
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

enum ParseConstants {
static let sdk = "swift"
static let version = "5.12.0"
static let version = "5.12.1"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand All @@ -26,7 +26,7 @@
static let deviceType = "tvos"
#elseif os(watchOS)
static let deviceType = "applewatch"
#elseif os(visionOS)

Check warning on line 29 in Sources/ParseSwift/ParseConstants.swift

View workflow job for this annotation

GitHub Actions / xcode-test-5_7

unknown operating system for build configuration 'os'

Check warning on line 29 in Sources/ParseSwift/ParseConstants.swift

View workflow job for this annotation

GitHub Actions / xcode-test-5_7

unknown operating system for build configuration 'os'
static let deviceType = "visionos"
#elseif os(Linux)
static let deviceType = "linux"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class APICommandMultipleAttemptsTests: XCTestCase {
try await ParseStorage.shared.deleteAll()
}

actor Result: Sendable {
actor Result {
var attempts = 0

func incrementAttempts() {
Expand Down
Loading