Skip to content

Commit 3f02f59

Browse files
authored
refactor: Remove extra Hashable conformance for ParseObject (#182)
* fix: Remove extra Hashable conformance for ParseObject * remove more double conformance * make public version of encoding ParseObject * remove public encoder * use xcbeautify in CI * Update ci.yml * doc nits * Update ci.yml * Update ci.yml * test not running installation tests on Windows * disable more windows using Installation * revert testing windows * Update ci.yml
1 parent b56de0a commit 3f02f59

21 files changed

+93
-62
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
action: 'test'
3838
steps:
3939
- uses: actions/checkout@v4
40-
- name: Install SwiftLint
40+
- name: Install Extra Packages
4141
run: brew install swiftlint
4242
- name: Create and set the default keychain
4343
run: |
@@ -46,7 +46,7 @@ jobs:
4646
security unlock-keychain -p "" temporary
4747
security set-keychain-settings -lut 7200 temporary
4848
- name: Build-Test
49-
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift -derivedDataPath DerivedData -destination ${{ matrix.destination }} ${{ matrix.action }} | xcpretty -c
49+
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift -derivedDataPath DerivedData -destination ${{ matrix.destination }} ${{ matrix.action }} 2>&1 | xcbeautify --renderer github-actions
5050
env:
5151
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
5252
- name: Prepare codecov
@@ -80,7 +80,7 @@ jobs:
8080
- name: Install SwiftLint
8181
run: brew install swiftlint
8282
- name: Build-Test
83-
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-code-coverage | xcpretty -c
83+
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-code-coverage 2>&1 | xcbeautify --renderer github-actions
8484
env:
8585
DEVELOPER_DIR: ${{ env.CI_XCODE_LATEST }}
8686
- name: Prepare codecov
@@ -108,7 +108,7 @@ jobs:
108108
steps:
109109
- uses: actions/checkout@v4
110110
- name: Build-Test
111-
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift -destination platform\=iOS\ Simulator,name\=iPhone\ 13\ Pro\ Max -derivedDataPath DerivedData build | xcpretty -c
111+
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift -destination platform\=iOS\ Simulator,name\=iPhone\ 13\ Pro\ Max -derivedDataPath DerivedData build 2>&1 | xcbeautify --renderer github-actions
112112
env:
113113
DEVELOPER_DIR: ${{ env.CI_XCODE_OLDEST }}
114114

@@ -141,11 +141,11 @@ jobs:
141141
- uses: actions/checkout@v4
142142
- uses: compnerd/[email protected]
143143
with:
144-
branch: swift-5.10-release
145-
tag: 5.10-RELEASE
144+
branch: swift-5.10.1-release
145+
tag: 5.10.1-RELEASE
146146
- name: Build
147147
run: |
148-
swift build -v
148+
swift build --enable-test-discovery -v
149149
- name: Upload coverage to Codecov
150150
uses: codecov/codecov-action@v4
151151
with:

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.11.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.3...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.11.3
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.2...5.11.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.3/documentation/parseswift)
10+
11+
__Fixes__
12+
* Remove all double conformance of Hashable and Equatable ([#182](https://github.com/netreconlab/Parse-Swift/pull/182)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.11.2
915
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.1...5.11.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.2/documentation/parseswift)
1016

Sources/ParseSwift/API/API+NonParseBodyCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal extension API.NonParseBodyCommand {
145145
objectsSavedBeforeThisOne: [String: PointerType]?,
146146
// swiftlint:disable:next line_length
147147
filesSavedBeforeThisOne: [String: ParseFile]?) async throws -> RESTBatchCommandTypeEncodablePointer<AnyCodable> {
148-
try await yieldIfNotInitialized()
148+
149149
let defaultACL = try? await ParseACL.defaultACL()
150150
let batchCommands = try objects.compactMap { (object) -> API.BatchCommand<AnyCodable, PointerType>? in
151151
guard var objectable = object as? Objectable else {

Sources/ParseSwift/Coding/ParseEncoder.swift

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ extension Dictionary: _JSONStringDictionaryEncodableMarker where Key == String,
5050
/** An object that encodes Parse instances of a data type as JSON objects.
5151
- note: `JSONEncoder` facilitates the encoding of `Encodable` values into JSON.
5252
`ParseEncoder` facilitates the encoding of `ParseEncodable` values into JSON.
53-
All Credit to Apple, this is a custom encoder with capability of skipping keys at runtime.
54-
ParseEncoder matches the features of the [Swift 5.4 JSONEncoder ](https://github.com/apple/swift/blob/main/stdlib/public/Darwin/Foundation/JSONEncoder.swift).
55-
Update commits as needed for improvement.
53+
All Credit to Apple for the baseline encoder. The `ParseEncoder` is a custom encoder
54+
with capability of skipping keys at runtime and encoding objects into a digestable format
55+
for a [parse-server](https://github.com/parse-community/parse-server).
56+
`ParseEncoder` matches the features of the [Swift 5.4 JSONEncoder ](https://github.com/apple/swift/blob/main/stdlib/public/Darwin/Foundation/JSONEncoder.swift).
57+
Update comments as needed for improvement.
5658
*/
5759
public struct ParseEncoder: Sendable {
5860
let dateEncodingStrategy: JSONEncoder.DateEncodingStrategy?
@@ -109,11 +111,13 @@ public struct ParseEncoder: Sendable {
109111
self.outputFormatting = outputFormatting
110112
}
111113

112-
func encode(_ value: Encodable,
113-
acl: ParseACL? = nil,
114-
batching: Bool = false,
115-
objectsSavedBeforeThisOne: [String: PointerType]? = nil,
116-
filesSavedBeforeThisOne: [String: ParseFile]? = nil) throws -> Data {
114+
func encode(
115+
_ value: Encodable,
116+
acl: ParseACL? = nil,
117+
batching: Bool = false,
118+
objectsSavedBeforeThisOne: [String: PointerType]? = nil,
119+
filesSavedBeforeThisOne: [String: ParseFile]? = nil
120+
) throws -> Data {
117121
var keysToSkip = SkipKeys.none.keys()
118122
if batching {
119123
keysToSkip = SkipKeys.object.keys()
@@ -137,53 +141,76 @@ public struct ParseEncoder: Sendable {
137141
/**
138142
Encodes an instance of the indicated `ParseEncodable`.
139143
- parameter value: The `ParseEncodable` instance to encode.
144+
- parameter acl: The `ParseACL` to add to the value if it is an `ParseObject`. Defaults to `nil`.
140145
- parameter skipKeys: The set of keys to skip during encoding.
141146
*/
142-
public func encode<T: ParseEncodable>(_ value: T,
143-
acl: ParseACL? = nil,
144-
skipKeys: SkipKeys) throws -> Data {
145-
let encoder = _ParseEncoder(codingPath: [], dictionary: NSMutableDictionary(), skippingKeys: skipKeys.keys())
147+
public func encode<T: ParseEncodable>(
148+
_ value: T,
149+
acl: ParseACL? = nil,
150+
skipKeys: SkipKeys
151+
) throws -> Data {
152+
let encoder = _ParseEncoder(
153+
codingPath: [],
154+
dictionary: NSMutableDictionary(),
155+
skippingKeys: skipKeys.keys()
156+
)
146157
if let dateEncodingStrategy = dateEncodingStrategy {
147158
encoder.dateEncodingStrategy = dateEncodingStrategy
148159
}
149160
if let outputFormatting = outputFormatting {
150161
encoder.outputFormatting = outputFormatting
151162
}
152-
return try encoder.encodeObject(value,
153-
acl: acl,
154-
collectChildren: false,
155-
uniquePointer: nil,
156-
objectsSavedBeforeThisOne: nil,
157-
filesSavedBeforeThisOne: nil).encoded
163+
let encodedData = try encoder.encodeObject(
164+
value,
165+
acl: acl,
166+
collectChildren: false,
167+
uniquePointer: nil,
168+
objectsSavedBeforeThisOne: nil,
169+
filesSavedBeforeThisOne: nil
170+
).encoded
171+
172+
return encodedData
158173
}
159174

160175
// swiftlint:disable large_tuple
161-
internal func encode<T: ParseObject>(_ value: T,
162-
acl: ParseACL? = nil,
163-
collectChildren: Bool,
164-
objectsSavedBeforeThisOne: [String: PointerType]?,
165-
filesSavedBeforeThisOne: [String: ParseFile]?) throws -> (encoded: Data,
166-
unique: PointerType?,
167-
unsavedChildren: [Encodable]) {
176+
func encode<T: ParseObject>(
177+
_ value: T,
178+
acl: ParseACL? = nil,
179+
collectChildren: Bool,
180+
objectsSavedBeforeThisOne: [String: PointerType]?,
181+
filesSavedBeforeThisOne: [String: ParseFile]?
182+
) throws -> (
183+
encoded: Data,
184+
unique: PointerType?,
185+
unsavedChildren: [Encodable]
186+
) {
168187
let keysToSkip: Set<String>!
169188
if !Parse.configuration.isRequiringCustomObjectIds {
170189
keysToSkip = SkipKeys.object.keys()
171190
} else {
172191
keysToSkip = SkipKeys.customObjectId.keys()
173192
}
174-
let encoder = _ParseEncoder(codingPath: [], dictionary: NSMutableDictionary(), skippingKeys: keysToSkip)
193+
let encoder = _ParseEncoder(
194+
codingPath: [],
195+
dictionary: NSMutableDictionary(),
196+
skippingKeys: keysToSkip
197+
)
175198
if let dateEncodingStrategy = dateEncodingStrategy {
176199
encoder.dateEncodingStrategy = dateEncodingStrategy
177200
}
178201
if let outputFormatting = outputFormatting {
179202
encoder.outputFormatting = outputFormatting
180203
}
181-
return try encoder.encodeObject(value,
182-
acl: acl,
183-
collectChildren: collectChildren,
184-
uniquePointer: try? value.toPointer(),
185-
objectsSavedBeforeThisOne: objectsSavedBeforeThisOne,
186-
filesSavedBeforeThisOne: filesSavedBeforeThisOne)
204+
let encodedObject = try encoder.encodeObject(
205+
value,
206+
acl: acl,
207+
collectChildren: collectChildren,
208+
uniquePointer: try? value.toPointer(),
209+
objectsSavedBeforeThisOne: objectsSavedBeforeThisOne,
210+
filesSavedBeforeThisOne: filesSavedBeforeThisOne
211+
)
212+
213+
return encodedObject
187214
}
188215

189216
internal func encode(_ value: ParseEncodable,

Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
- Updated: The object has been updated, and is still a part of the query.
1717
- Deleted: The object has been deleted, and is no longer included in the query.
1818
*/
19-
public enum Event<T: ParseObject>: Equatable {
19+
public enum Event<T: ParseObject>: Equatable, Sendable {
2020
/// The object has been updated, and is now included in the query.
2121
case entered(T)
2222

Sources/ParseSwift/LiveQuery/Operations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ enum OperationErrorResponse: String, Codable {
2626

2727
// An opaque placeholder structed used to ensure that we type-safely create request IDs and do not shoot ourself in
2828
// the foot with array indexes.
29-
struct RequestId: Hashable, Equatable, Codable {
29+
struct RequestId: Hashable, Codable {
3030
let value: Int
3131
}

Sources/ParseSwift/Objects/ParseObject.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public protocol ParseObject: ParseTypeable,
4444
Fetchable,
4545
Savable,
4646
Deletable,
47-
Identifiable,
48-
Hashable {
47+
Identifiable {
4948

5049
/**
5150
A JSON encoded version of this `ParseObject` before `.set()` or

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

Sources/ParseSwift/Protocols/ParseConfig.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ extension ParseConfig {
9494
}
9595
}
9696

97-
internal struct ConfigUpdateBody<T>: ParseTypeable, Decodable where T: ParseConfig {
97+
internal struct ConfigUpdateBody<T>: ParseTypeable where T: ParseConfig {
9898
let params: T
9999
}
100100

101101
// MARK: Current
102-
struct CurrentConfigContainer<T: ParseConfig>: Codable, Equatable {
102+
struct CurrentConfigContainer<T: ParseConfig>: Codable, Hashable {
103103
var currentConfig: T?
104104
}
105105

Sources/ParseSwift/Protocols/ParsePointerable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension ParsePointer {
2929
}
3030
}
3131

32-
public protocol ParsePointerObject: ParsePointer, ParseTypeable, Fetchable, Hashable {
32+
public protocol ParsePointerObject: ParsePointer, ParseTypeable, Fetchable {
3333
associatedtype Object: ParseObject
3434
}
3535

0 commit comments

Comments
 (0)