Skip to content

Commit 37a2247

Browse files
authored
fix: improve equatable comparison of QueryConstraint (#275)
* fix: improve equatable comparison of QueryConstraint * nits
1 parent af447a6 commit 37a2247

21 files changed

+194
-158
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
### main
44

5-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.1...main)
5+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.2...main)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 2.2.2
9+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.1...2.2.2)
10+
11+
__Fixes__
12+
- Improve equatable comparison of QueryConstraint ([#275](https://github.com/parse-community/Parse-Swift/pull/275)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 2.2.1
915
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.0...2.2.1)
1016

1117
__Fixes__
12-
- Set the default cache policy for `ParseFile` to the default policy set when initializing the SDK ([#274](https://github.com/parse-community/Parse-Swift/pull/274)), thanks to [Corey Baker](https://github.com/cbaker6).
18+
- Set the default cache policy for ParseFile to the default policy set when initializing the SDK ([#274](https://github.com/parse-community/Parse-Swift/pull/274)), thanks to [Corey Baker](https://github.com/cbaker6).
1319

1420
### 2.2.0
1521
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.1.0...2.2.0)
@@ -18,7 +24,7 @@ __Improvements__
1824
- Added ability to fetch ParsePointer using async/await ([#271](https://github.com/parse-community/Parse-Swift/pull/271)), thanks to [Corey Baker](https://github.com/cbaker6).
1925

2026
__Fixes__
21-
- By default, don't use cache when fetching ParseObject's and `ParseFile`s. Developers can choose to fetch from cache if desired by passing the necessary option while fetching. Fixed a bug when the incorrect file location for a dowloaded ParseFile was being cached ([#272](https://github.com/parse-community/Parse-Swift/pull/272)), thanks to [Corey Baker](https://github.com/cbaker6).
27+
- By default, don't use cache when fetching ParseObject's and ParseFile's. Developers can choose to fetch from cache if desired by passing the necessary option while fetching. Fixed a bug when the incorrect file location for a dowloaded ParseFile was being cached ([#272](https://github.com/parse-community/Parse-Swift/pull/272)), thanks to [Corey Baker](https://github.com/cbaker6).
2228

2329
### 2.1.0
2430
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.3...2.1.0)

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 70 additions & 52 deletions
Large diffs are not rendered by default.

Sources/ParseSwift/Coding/Extensions.swift

Lines changed: 0 additions & 61 deletions
This file was deleted.

Sources/ParseSwift/Coding/ParseCoding.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,48 @@ extension ParseCoding {
4141
}
4242
}
4343

44+
// MARK: Coding
45+
public extension ParseObject {
46+
47+
/// The Parse encoder is used to JSON encode all `ParseObject`s and
48+
/// types in a way meaninful for a Parse Server to consume.
49+
static func getEncoder() -> ParseEncoder {
50+
return ParseCoding.parseEncoder()
51+
}
52+
53+
/// The Parse encoder is used to JSON encode all `ParseObject`s and
54+
/// types in a way meaninful for a Parse Server to consume.
55+
func getEncoder() -> ParseEncoder {
56+
return Self.getEncoder()
57+
}
58+
59+
/// The JSON encoder setup with the correct `dateEncodingStrategy`
60+
/// strategy to send data to a Parse Server.
61+
static func getJSONEncoder() -> JSONEncoder {
62+
return ParseCoding.jsonEncoder()
63+
}
64+
65+
/// The JSON encoder setup with the correct `dateEncodingStrategy`
66+
/// strategy to send data to a Parse Server.
67+
func getJSONEncoder() -> JSONEncoder {
68+
return Self.getJSONEncoder()
69+
}
70+
71+
/// The JSON decoder setup with the correct `dateDecodingStrategy`
72+
/// strategy to decode data from a Parse Server. This encoder is used to decode all data received
73+
/// from the server.
74+
static func getDecoder() -> JSONDecoder {
75+
ParseCoding.jsonDecoder()
76+
}
77+
78+
/// The JSON decoder setup with the correct `dateDecodingStrategy`
79+
/// strategy to decode data from a Parse Server. This encoder is used to decode all data received
80+
/// from the server.
81+
func getDecoder() -> JSONDecoder {
82+
Self.getDecoder()
83+
}
84+
}
85+
4486
// MARK: Dates
4587
extension ParseCoding {
4688
enum DateEncodingKeys: String, CodingKey {

Sources/ParseSwift/Internal/Data+hexString.swift renamed to Sources/ParseSwift/Extensions/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Data+hexString.swift
2+
// Data.swift
33
// ParseSwift
44
//
55
// Created by Corey Baker on 2/14/21.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Date.swift
3+
// ParseSwift
4+
//
5+
// Created by Corey Baker on 11/4/21.
6+
// Copyright © 2021 Parse Community. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
// MARK: Date
12+
internal extension Date {
13+
func parseFormatted() -> String {
14+
return ParseCoding.dateFormatter.string(from: self)
15+
}
16+
17+
var parseRepresentation: [String: String] {
18+
return ["__type": "Date", "iso": parseFormatted()]
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Encodable.swift
3+
// ParseSwift
4+
//
5+
// Created by Corey Baker on 11/4/21.
6+
// Copyright © 2021 Parse Community. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
internal extension Encodable {
12+
func isEqual(_ other: Encodable) -> Bool {
13+
guard let lhsData = try? ParseCoding.parseEncoder().encode(self),
14+
let lhsString = String(data: lhsData, encoding: .utf8),
15+
let rhsData = try? ParseCoding.parseEncoder().encode(other),
16+
let rhsString = String(data: rhsData, encoding: .utf8) else {
17+
return false
18+
}
19+
return lhsString == rhsString
20+
}
21+
}

Sources/ParseSwift/API/URLCache+extensions.swift renamed to Sources/ParseSwift/Extensions/URLCache.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// URLCache+extensions.swift
2+
// URLCache.swift
33
// ParseSwift
44
//
55
// Created by Corey Baker on 7/17/21.
@@ -11,7 +11,7 @@ import Foundation
1111
import FoundationNetworking
1212
#endif
1313

14-
extension URLCache {
14+
internal extension URLCache {
1515
static let parse: URLCache = {
1616
guard let cacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
1717
return URLCache(memoryCapacity: ParseSwift.configuration.cacheMemoryCapacity,

Sources/ParseSwift/API/URLSession+extensions.swift renamed to Sources/ParseSwift/Extensions/URLSession.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//
2-
// URLSession+extensions.swift
2+
// URLSession.swift
33
// ParseSwift
44
//
55
// Original file, URLSession+sync.swift, created by Florent Vilmart on 17-09-24.
6-
// Name change to URLSession+extensions.swift and support for sync/async by Corey Baker on 7/25/20.
6+
// Name change to URLSession.swift and support for sync/async by Corey Baker on 7/25/20.
77
// Copyright © 2020 Parse Community. All rights reserved.
88
//
99

@@ -12,7 +12,7 @@ import Foundation
1212
import FoundationNetworking
1313
#endif
1414

15-
extension URLSession {
15+
internal extension URLSession {
1616
static let parse: URLSession = {
1717
if !ParseSwift.configuration.isTestingSDK {
1818
let configuration = URLSessionConfiguration.default
@@ -29,11 +29,11 @@ extension URLSession {
2929
}
3030
}()
3131

32-
internal func makeResult<U>(request: URLRequest,
33-
responseData: Data?,
34-
urlResponse: URLResponse?,
35-
responseError: Error?,
36-
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
32+
func makeResult<U>(request: URLRequest,
33+
responseData: Data?,
34+
urlResponse: URLResponse?,
35+
responseError: Error?,
36+
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
3737
guard let response = urlResponse else {
3838
guard let parseError = responseError as? ParseError else {
3939
return .failure(ParseError(code: .unknownError,
@@ -87,11 +87,11 @@ extension URLSession {
8787
message: "Unable to sync with parse-server: \(String(describing: urlResponse))."))
8888
}
8989

90-
internal func makeResult<U>(request: URLRequest,
91-
location: URL?,
92-
urlResponse: URLResponse?,
93-
responseError: Error?,
94-
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
90+
func makeResult<U>(request: URLRequest,
91+
location: URL?,
92+
urlResponse: URLResponse?,
93+
responseError: Error?,
94+
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
9595
guard let response = urlResponse else {
9696
guard let parseError = responseError as? ParseError else {
9797
return .failure(ParseError(code: .unknownError,
@@ -125,7 +125,7 @@ extension URLSession {
125125
message: "Unable to sync with parse-server: \(response)."))
126126
}
127127

128-
internal func dataTask<U>(
128+
func dataTask<U>(
129129
with request: URLRequest,
130130
mapper: @escaping (Data) throws -> U,
131131
completion: @escaping(Result<U, ParseError>) -> Void
@@ -141,8 +141,8 @@ extension URLSession {
141141
}
142142
}
143143

144-
extension URLSession {
145-
internal func uploadTask<U>( // swiftlint:disable:this function_parameter_count
144+
internal extension URLSession {
145+
func uploadTask<U>( // swiftlint:disable:this function_parameter_count
146146
callbackQueue: DispatchQueue,
147147
with request: URLRequest,
148148
from data: Data?,
@@ -176,7 +176,7 @@ extension URLSession {
176176
}
177177
}
178178

179-
internal func downloadTask<U>(
179+
func downloadTask<U>(
180180
callbackQueue: DispatchQueue,
181181
with request: URLRequest,
182182
progress: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)?,
@@ -210,7 +210,7 @@ extension URLSession {
210210
task.resume()
211211
}
212212

213-
internal func downloadTask<U>(
213+
func downloadTask<U>(
214214
with request: URLRequest,
215215
mapper: @escaping (Data) throws -> U,
216216
completion: @escaping(Result<U, ParseError>) -> Void

Sources/ParseSwift/Internal/BaseConfig.swift renamed to Sources/ParseSwift/InternalObjects/BaseConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
import Foundation
1010

11-
struct BaseConfig: ParseConfig { }
11+
struct BaseConfig: ParseConfig {}

Sources/ParseSwift/LiveQuery/Protocols/QuerySubscribable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Foundation
1313
You can use this protocol on any custom class of yours, instead of `Subscription` or
1414
`SubscriptionCallback`, if it fits your use case better.
1515
*/
16-
public protocol QuerySubscribable: AnyObject {
16+
public protocol QuerySubscribable: AnyObject {
1717

1818
/// The `ParseObject` associated with this subscription.
1919
associatedtype Object: ParseObject

Sources/ParseSwift/Objects/ParseSession.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ extension ParseSession {
5151
if let objectId = objectId {
5252
return .session(objectId: objectId)
5353
}
54-
5554
return .sessions
5655
}
5756
}

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

Sources/ParseSwift/Operations/ParseOperation.swift renamed to Sources/ParseSwift/Types/ParseOperation.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import Foundation
1313
For example, setting, deleting, or incrementing a value are all `ParseOperation`'s.
1414
`ParseOperation` themselves can be considered to be immutable.
1515

16-
In most cases, you should not call this class directly as a `ParseOperation` can be
17-
indirectly created from any `ParseObject` by using its `operation` property.
16+
In most cases, you do not need to create an instance of `ParseOperation` directly as it can be
17+
indirectly created from any `ParseObject` by using the respective `operation` property.
1818
*/
1919
public struct ParseOperation<T>: Savable where T: ParseObject {
2020

@@ -38,7 +38,7 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
3838
throw ParseError(code: .unknownError, message: "Target shouldn't be nil")
3939
}
4040
var mutableOperation = self
41-
if !isEqual(target[keyPath: key.1], to: value) {
41+
if !target[keyPath: key.1].isEqual(value) {
4242
mutableOperation.operations[key.0] = value
4343
mutableOperation.target?[keyPath: key.1] = value
4444
}
@@ -397,16 +397,6 @@ public struct ParseOperation<T>: Savable where T: ParseObject {
397397
try value.encode(to: encoder)
398398
}
399399
}
400-
401-
func isEqual(_ lhs: Encodable, to rhs: Encodable) -> Bool {
402-
guard let lhsData = try? ParseCoding.parseEncoder().encode(lhs),
403-
let lhsString = String(data: lhsData, encoding: .utf8),
404-
let rhsData = try? ParseCoding.parseEncoder().encode(rhs),
405-
let rhsString = String(data: rhsData, encoding: .utf8) else {
406-
return false
407-
}
408-
return lhsString == rhsString
409-
}
410400
}
411401

412402
// MARK: Savable

Sources/ParseSwift/Types/ParseRelation.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import Foundation
1111
/**
1212
The `ParseRelation` class that is used to access all of the children of a many-to-many relationship.
1313
Each instance of `ParseRelation` is associated with a particular parent object and key.
14+
15+
In most cases, you do not need to create an instance of `ParseOperation` directly as it can be
16+
indirectly created from any `ParseObject` by using the respective `relation` property.
1417
*/
1518
public struct ParseRelation<T>: Codable, Hashable where T: ParseObject {
1619
internal let __type: String = "Relation" // swiftlint:disable:this identifier_name

Sources/ParseSwift/Types/Query.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ public struct QueryConstraint: Encodable, Equatable {
6464

6565
public static func == (lhs: QueryConstraint, rhs: QueryConstraint) -> Bool {
6666
guard lhs.key == rhs.key,
67-
lhs.comparator == rhs.comparator,
68-
let lhsObject = lhs.value as? NSObject,
69-
let rhsObject = rhs.value as? NSObject else {
67+
lhs.comparator == rhs.comparator else {
7068
return false
7169
}
72-
return lhsObject == rhsObject
70+
return lhs.value.isEqual(rhs.value)
7371
}
7472
}
7573

0 commit comments

Comments
 (0)