Skip to content

Commit

Permalink
fix: remove all generic shadow warnings (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Jun 20, 2023
1 parent e92241c commit 424ebff
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 39 deletions.
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
# Parse-Swift Changelog

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

__Fixes__
* Remove all generic shadow warnings in Swift 5.9 ([#120](https://github.com/netreconlab/Parse-Swift/pull/120)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.7.2
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.1...5.7.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.2/documentation/parseswift)

__Fixes__
* ParsePolygon encoding during a save and decoding resulted in (longitude, latitude) when it should be
(latitude, longitude). If a developer used ParseSwift <= 5.7.1
to save/update ParsePolygon's, they will need to update the respective ParseObjects by swapping the latitude
and longitude manually. Deprecated withinPolygon() query constraint for geoPoint() and polygonContains() for
polygon() ([#118](https://github.com/netreconlab/Parse-Swift/pull/118)), thanks to
[Corey Baker](https://github.com/cbaker6).
* ParsePolygon encoding during a save and decoding resulted in (longitude, latitude) when it should be (latitude, longitude). If a developer used ParseSwift <= 5.7.1 to save/update ParsePolygon's, they will need to update the respective ParseObjects by swapping the latitude and longitude manually. Deprecated withinPolygon() query constraint for geoPoint() and polygonContains() for polygon() ([#118](https://github.com/netreconlab/Parse-Swift/pull/118)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.7.1
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.0...5.7.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.1/documentation/parseswift)
Expand Down
38 changes: 19 additions & 19 deletions Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ internal extension API.Command {
}

// MARK: Saving ParseObjects
static func save<T>(_ object: T,
static func save<V>(_ object: V,
original data: Data?,
ignoringCustomObjectIdConfig: Bool,
batching: Bool = false) async throws -> API.Command<T, T> where T: ParseObject {
batching: Bool = false) async throws -> API.Command<V, V> where V: ParseObject {
if Parse.configuration.isRequiringCustomObjectIds
&& object.objectId == nil && !ignoringCustomObjectIdConfig {
throw ParseError(code: .missingObjectId, message: "objectId must not be nil")
Expand All @@ -417,77 +417,77 @@ internal extension API.Command {
return try await create(object)
}

static func create<T>(_ object: T) async throws -> API.Command<T, T> where T: ParseObject {
static func create<V>(_ object: V) async throws -> API.Command<V, V> where V: ParseObject {
var object = object
if object.ACL == nil,
let acl = try? await ParseACL.defaultACL() {
object.ACL = acl
}
let mapper = { (data) -> T in
let mapper = { (data) -> V in
try ParseCoding.jsonDecoder().decode(CreateResponse.self, from: data).apply(to: object)
}
return API.Command<T, T>(method: .POST,
return API.Command<V, V>(method: .POST,
path: try await object.endpoint(.POST),
body: object,
mapper: mapper)
}

static func replace<T>(_ object: T,
original data: Data?) throws -> API.Command<T, T> where T: ParseObject {
static func replace<V>(_ object: V,
original data: Data?) throws -> API.Command<V, V> where V: ParseObject {
guard object.objectId != nil else {
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
}
let mapper = { (mapperData: Data) -> T in
let mapper = { (mapperData: Data) -> V in
var updatedObject = object
updatedObject.originalData = nil
updatedObject = try ParseCoding
.jsonDecoder()
.decode(ReplaceResponse.self, from: mapperData)
.apply(to: updatedObject)
guard let originalData = data,
let original = try? ParseCoding.jsonDecoder().decode(T.self,
let original = try? ParseCoding.jsonDecoder().decode(V.self,
from: originalData),
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try updatedObject.merge(with: original)
}
return API.Command<T, T>(method: .PUT,
return API.Command<V, V>(method: .PUT,
path: object.endpoint,
body: object,
mapper: mapper)
}

static func update<T>(_ object: T,
original data: Data?) throws -> API.Command<T, T> where T: ParseObject {
static func update<V>(_ object: V,
original data: Data?) throws -> API.Command<V, V> where V: ParseObject {
guard object.objectId != nil else {
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
}
let mapper = { (mapperData: Data) -> T in
let mapper = { (mapperData: Data) -> V in
var updatedObject = object
updatedObject.originalData = nil
updatedObject = try ParseCoding
.jsonDecoder()
.decode(UpdateResponse.self, from: mapperData)
.apply(to: updatedObject)
guard let originalData = data,
let original = try? ParseCoding.jsonDecoder().decode(T.self,
let original = try? ParseCoding.jsonDecoder().decode(V.self,
from: originalData),
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try updatedObject.merge(with: original)
}
return API.Command<T, T>(method: .PATCH,
return API.Command<V, V>(method: .PATCH,
path: object.endpoint,
body: object,
mapper: mapper)
}

// MARK: Fetching ParseObjects
static func fetch<T>(_ object: T, include: [String]?) throws -> API.Command<T, T> where T: ParseObject {
static func fetch<V>(_ object: V, include: [String]?) throws -> API.Command<V, V> where V: ParseObject {
guard object.objectId != nil else {
throw ParseError(code: .missingObjectId,
message: "objectId must not be nil")
Expand All @@ -498,12 +498,12 @@ internal extension API.Command {
params = ["include": "\(Set(includeParams))"]
}

return API.Command<T, T>(
return API.Command<V, V>(
method: .GET,
path: object.endpoint,
params: params
) { (data) -> T in
try ParseCoding.jsonDecoder().decode(T.self, from: data)
) { (data) -> V in
try ParseCoding.jsonDecoder().decode(V.self, from: data)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/API+NonParseBodyCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal extension API {
internal extension API.NonParseBodyCommand {

// MARK: Deleting
static func delete<T>(_ object: T) throws -> API.NonParseBodyCommand<NoBody, NoBody> where T: ParseObject {
static func delete<V>(_ object: V) throws -> API.NonParseBodyCommand<NoBody, NoBody> where V: ParseObject {
guard object.isSaved else {
throw ParseError(code: .otherCause,
message: "Cannot delete an object without an objectId")
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public enum Event<T: ParseObject>: Equatable {
}
}

public static func == <T>(lhs: Event<T>, rhs: Event<T>) -> Bool {
public static func == <U>(lhs: Event<U>, rhs: Event<U>) -> Bool {
switch (lhs, rhs) {
case (.entered(let obj1), .entered(let obj2)): return obj1 == obj2
case (.left(let obj1), .left(let obj2)): return obj1 == obj2
Expand Down
12 changes: 6 additions & 6 deletions Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public extension Query {
- returns: Your subscription handler, for easy chaining.
- throws: An error of type `ParseError`.
*/
static func subscribe<T: QuerySubscribable>(_ handler: T) async throws -> T {
static func subscribe<V: QuerySubscribable>(_ handler: V) async throws -> V {
try await ParseLiveQuery.client().subscribe(handler)
}

Expand All @@ -904,7 +904,7 @@ public extension Query {
- returns: Your subscription handler, for easy chaining.
- throws: An error of type `ParseError`.
*/
static func subscribe<T: QuerySubscribable>(_ handler: T, client: ParseLiveQuery) async throws -> T {
static func subscribe<V: QuerySubscribable>(_ handler: V, client: ParseLiveQuery) async throws -> V {
try await ParseLiveQuery.client().subscribe(handler)
}

Expand Down Expand Up @@ -957,7 +957,7 @@ public extension Query {
- parameter handler: The specific handler to unsubscribe from.
- throws: An error of type `ParseError`.
*/
func unsubscribe<T: QuerySubscribable>(_ handler: T) async throws {
func unsubscribe<V: QuerySubscribable>(_ handler: V) async throws {
try await ParseLiveQuery.client().unsubscribe(handler)
}

Expand All @@ -968,7 +968,7 @@ public extension Query {
- parameter client: A specific client.
- throws: An error of type `ParseError`.
*/
func unsubscribe<T: QuerySubscribable>(_ handler: T, client: ParseLiveQuery) async throws {
func unsubscribe<V: QuerySubscribable>(_ handler: V, client: ParseLiveQuery) async throws {
try await client.unsubscribe(handler)
}
}
Expand All @@ -981,7 +981,7 @@ public extension Query {
- parameter handler: The specific handler to update.
- throws: An error of type `ParseError`.
*/
func update<T: QuerySubscribable>(_ handler: T) async throws {
func update<V: QuerySubscribable>(_ handler: V) async throws {
try await ParseLiveQuery.client().update(handler)
}

Expand All @@ -992,7 +992,7 @@ public extension Query {
- parameter client: A specific client.
- throws: An error of type `ParseError`.
*/
func update<T: QuerySubscribable>(_ handler: T, client: ParseLiveQuery) async throws {
func update<V: QuerySubscribable>(_ handler: V, client: ParseLiveQuery) async throws {
try await client.update(handler)
}
}
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 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "5.7.2"
static let version = "5.7.3"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
3 changes: 3 additions & 0 deletions Sources/ParseSwift/Types/ParseServer+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public extension ParseServer {
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: Status of ParseServer.
- throws: An error of type `ParseError`.
- requires: `.usePrimaryKey` has to be available. It is recommended to only
use the primary key in server-side applications where the key is kept secure and not
exposed to the public.
*/
static func information(options: API.Options = []) async throws -> Information {
try await withCheckedThrowingContinuation { continuation in
Expand Down
3 changes: 3 additions & 0 deletions Sources/ParseSwift/Types/ParseServer+combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public extension ParseServer {
Retrieves any information provided by the server *asynchronously*. Publishes when complete.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- requires: `.usePrimaryKey` has to be available. It is recommended to only
use the primary key in server-side applications where the key is kept secure and not
exposed to the public.
*/
static func informationPublisher(options: API.Options = []) -> Future<Information, ParseError> {
Future { promise in
Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseSwift/Types/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
Self.className
}

struct AggregateBody<T>: Codable where T: ParseObject {
struct AggregateBody<V>: Codable where V: ParseObject {
let pipeline: [[String: AnyCodable]]?
let hint: AnyCodable?
let explain: Bool?
let includeReadPreference: String?

init(query: Query<T>) {
init(query: Query<V>) {
pipeline = query.pipeline
hint = query.hint
explain = query.explain
Expand All @@ -77,13 +77,13 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
}
}

struct DistinctBody<T>: Codable where T: ParseObject {
struct DistinctBody<V>: Codable where V: ParseObject {
let hint: AnyCodable?
let explain: Bool?
let includeReadPreference: String?
let distinct: String?

init(query: Query<T>) {
init(query: Query<V>) {
distinct = query.distinct
hint = query.hint
explain = query.explain
Expand Down

0 comments on commit 424ebff

Please sign in to comment.