Skip to content

Commit 157401b

Browse files
authored
fix: App crash when using QueryConstraint (#193)
* fix: App crash when using QueryConstraint * Update ci.yml * fix tests
1 parent 54de43d commit 157401b

File tree

7 files changed

+124
-58
lines changed

7 files changed

+124
-58
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: macos-15
2323
strategy:
2424
matrix:
25-
destination: ['platform=iOS\ Simulator,OS=18.2,name=iPhone\ 16\ Pro\ Max', 'platform\=tvOS\ Simulator,OS=18.2,name\=Apple\ TV', 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 10\ \(42mm\)', 'platform=macOS', 'platform=visionOS\ Simulator,OS=2.2,name=Apple\ Vision\ Pro']
25+
destination: ['platform=iOS\ Simulator,OS=18.2,name=iPhone\ 16\ Pro\ Max', 'platform\=tvOS\ Simulator,OS=18.2,name\=Apple\ TV', 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 10\ \(46mm\)', 'platform=macOS', 'platform=visionOS\ Simulator,OS=2.2,name=Apple\ Vision\ Pro']
2626
action: ['test', 'build']
2727
exclude:
2828
- destination: 'platform=iOS\ Simulator,OS=18.2,name=iPhone\ 16\ Pro\ Max'
@@ -33,7 +33,7 @@ jobs:
3333
action: 'build'
3434
- destination: 'platform=visionOS\ Simulator,OS=2.2,name=Apple\ Vision\ Pro'
3535
action: 'test'
36-
- destination: 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 10\ \(42mm\)'
36+
- destination: 'platform=watchOS\ Simulator,name=Apple\ Watch\ Series\ 10\ \(46mm\)'
3737
action: 'test'
3838
steps:
3939
- uses: actions/checkout@v4

CHANGELOG.md

+7-1
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.4...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.5...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.5
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.4...5.11.5), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.5/documentation/parseswift)
10+
11+
__Fixes__
12+
* Fix app crash when using QueryConstraint == ([#193](https://github.com/netreconlab/Parse-Swift/pull/193)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.11.4
915
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.3...5.11.4), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.4/documentation/parseswift)
1016

Sources/ParseSwift/ParseConstants.swift

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

Sources/ParseSwift/Types/ParseConfiguration.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ public struct ParseConfiguration {
4848
/// - warning: This is experimental.
4949
public internal(set) var isUsingTransactions = false
5050

51-
/// Use the **$eq** query constraint when querying.
52-
/// - warning: This is known not to work for LiveQuery on Parse Servers <= 5.0.0.
51+
/// ParseSwift uses the **$eq** query constraint by default when querying.
52+
/// - warning: This method uses `$eq` and can
53+
/// be combined with all other `QueryConstaint`'s. It has the limitation of
54+
/// not to working for LiveQuery on Parse Servers `< 6.3.0`. If you are using
55+
/// an older Parse Server, you should use `equalToNoComparator()`
56+
@available(*, deprecated, message: "Changing has no effect. This will be remove in ParseSwift 6.0.0")
5357
public internal(set) var isUsingEqualQueryConstraint = false
5458

5559
/// Use **POST** instead of **GET** when making query calls.

Sources/ParseSwift/Types/QueryConstraint.swift

+67-38
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ public func <= <T>(key: String, value: T) -> QueryConstraint where T: Codable {
133133
- parameter value: The value to compare.
134134
- returns: The same instance of `QueryConstraint` as the receiver.
135135
- warning: See `equalTo` for more information.
136-
Behavior changes based on `ParseSwift.configuration.isUsingEqualQueryConstraint`
137-
where isUsingEqualQueryConstraint == true is known not to work for LiveQuery on
138-
Parse Servers <= 5.0.0.
136+
This method uses `$eq` and can
137+
be combined with all other `QueryConstaint`'s. It has the limitation of
138+
not to working for LiveQuery on Parse Servers `< 6.3.0`. If you are using
139+
an older Parse Server, you should use `equalToNoComparator()`
140+
instead.
139141
*/
140142
public func == <T>(key: String, value: T) -> QueryConstraint where T: Codable {
141143
equalTo(key: key, value: value)
@@ -145,23 +147,33 @@ public func == <T>(key: String, value: T) -> QueryConstraint where T: Codable {
145147
Add a constraint that requires that a key is equal to a value.
146148
- parameter key: The key that the value is stored in.
147149
- parameter value: The value to compare.
148-
- parameter usingEqComparator: Set to **true** to use **$eq** comparater,
149-
allowing for multiple `QueryConstraint`'s to be used on a single **key**.
150-
Setting to *false* may override any `QueryConstraint`'s on the same **key**.
151-
Defaults to `ParseSwift.configuration.isUsingEqualQueryConstraint`.
152150
- returns: The same instance of `QueryConstraint` as the receiver.
153-
- warning: `usingEqComparator == true` is known not to work for LiveQueries
154-
on Parse Servers <= 5.0.0.
155-
*/
156-
public func equalTo <T>(key: String,
157-
value: T,
158-
// swiftlint:disable:next line_length
159-
usingEqComparator: Bool = configuration.isUsingEqualQueryConstraint) -> QueryConstraint where T: Codable {
160-
if !usingEqComparator {
161-
return QueryConstraint(key: key, value: value)
162-
} else {
163-
return QueryConstraint(key: key, value: value, comparator: .equalTo)
164-
}
151+
- warning: This method uses `$eq` and can
152+
be combined with all other `QueryConstaint`'s. It has the limitation of
153+
not to working for LiveQuery on Parse Servers `< 6.3.0`. If you are using
154+
an older Parse Server, you should use `equalToNoComparator()`
155+
instead.
156+
*/
157+
public func equalTo<T>(
158+
key: String,
159+
value: T
160+
) -> QueryConstraint where T: Codable {
161+
QueryConstraint(key: key, value: value, comparator: .equalTo)
162+
}
163+
164+
/**
165+
Add a constraint that requires that a key is equal to a value.
166+
- parameter key: The key that the value is stored in.
167+
- parameter value: The value to compare.
168+
- returns: The same instance of `QueryConstraint` as the receiver.
169+
- warning: This `QueryConstaint` has the limitation of being able to be combined
170+
with other `QueryConstraint`'s. It does however work with all versions of LiveQuery.
171+
*/
172+
public func equalToNoComparator<T>(
173+
key: String,
174+
value: T
175+
) -> QueryConstraint where T: Codable {
176+
QueryConstraint(key: key, value: value)
165177
}
166178

167179
/**
@@ -171,9 +183,11 @@ public func equalTo <T>(key: String,
171183
- returns: The same instance of `QueryConstraint` as the receiver.
172184
- throws: An error of type `ParseError`.
173185
- warning: See `equalTo` for more information.
174-
Behavior changes based on `ParseSwift.configuration.isUsingEqualQueryConstraint`
175-
where isUsingEqualQueryConstraint == true is known not to work for LiveQuery on
176-
Parse Servers <= 5.0.0.
186+
This method uses `$eq` and can
187+
be combined with all other `QueryConstaint`'s. It has the limitation of
188+
not to working for LiveQuery on Parse Servers `< 6.3.0`. If you are using
189+
an older Parse Server, you should use `equalToNoComparator()`
190+
instead.
177191
*/
178192
public func == <T>(key: String, object: T) throws -> QueryConstraint where T: ParseObject {
179193
try equalTo(key: key, object: object)
@@ -183,24 +197,39 @@ public func == <T>(key: String, object: T) throws -> QueryConstraint where T: Pa
183197
Add a constraint that requires that a key is equal to a `ParseObject`.
184198
- parameter key: The key that the value is stored in.
185199
- parameter object: The `ParseObject` to compare.
186-
- parameter usingEqComparator: Set to **true** to use **$eq** comparater,
187-
allowing for multiple `QueryConstraint`'s to be used on a single **key**.
188-
Setting to *false* may override any `QueryConstraint`'s on the same **key**.
189-
Defaults to `ParseSwift.configuration.isUsingEqualQueryConstraint`.
190200
- returns: The same instance of `QueryConstraint` as the receiver.
191201
- throws: An error of type `ParseError`.
192-
- warning: `usingEqComparator == true` is known not to work for LiveQueries
193-
on Parse Servers <= 5.0.0.
194-
*/
195-
public func equalTo <T>(key: String,
196-
object: T,
197-
// swiftlint:disable:next line_length
198-
usingEqComparator: Bool = configuration.isUsingEqualQueryConstraint) throws -> QueryConstraint where T: ParseObject {
199-
if !usingEqComparator {
200-
return try QueryConstraint(key: key, value: object.toPointer())
201-
} else {
202-
return try QueryConstraint(key: key, value: object.toPointer(), comparator: .equalTo)
203-
}
202+
- warning: This method uses `$eq` and can
203+
be combined with all other `QueryConstaint`'s. It has the limitation of
204+
not to working for LiveQuery on Parse Servers `< 6.3.0`. If you are using
205+
an older Parse Server, you should use `equalToNoComparator()`
206+
instead.
207+
*/
208+
public func equalTo<T>(
209+
key: String,
210+
object: T
211+
) throws -> QueryConstraint where T: ParseObject {
212+
try QueryConstraint(
213+
key: key,
214+
value: object.toPointer(),
215+
comparator: .equalTo
216+
)
217+
}
218+
219+
/**
220+
Add a constraint that requires that a key is equal to a `ParseObject`.
221+
- parameter key: The key that the value is stored in.
222+
- parameter object: The `ParseObject` to compare.
223+
- returns: The same instance of `QueryConstraint` as the receiver.
224+
- throws: An error of type `ParseError`.
225+
- warning: This `QueryConstaint` has the limitation of being able to be combined
226+
with other `QueryConstraint`'s. It does however work with all versions of LiveQuery.
227+
*/
228+
public func equalToNoComparator<T>(
229+
key: String,
230+
object: T
231+
) throws -> QueryConstraint where T: ParseObject {
232+
try QueryConstraint(key: key, value: object.toPointer())
204233
}
205234

206235
/**

Tests/ParseSwiftTests/APICommandTests.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ class APICommandTests: XCTestCase {
408408
}
409409

410410
func testQueryWhereEncoding() async throws {
411-
let query = Level.query("name" == "[email protected]")
411+
let query = Level.query(
412+
equalToNoComparator(
413+
key: "name",
414+
415+
)
416+
)
412417
let parameters = try query.getQueryParameters()
413418

414419
let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(
@@ -432,7 +437,12 @@ class APICommandTests: XCTestCase {
432437
}
433438

434439
func testQueryWhereEncodingPlus() async throws {
435-
let query = Level.query("name" == "[email protected]")
440+
let query = Level.query(
441+
equalToNoComparator(
442+
key: "name",
443+
444+
)
445+
)
436446
let parameters = try query.getQueryParameters()
437447

438448
let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(

Tests/ParseSwiftTests/ParseQueryTests.swift

+29-12
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,16 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12101210
}
12111211
}
12121212

1213-
func testWhereKeyEqualTo() {
1213+
func testWhereKeyEqualToNoComparator() {
12141214
let expected: [String: String] = [
12151215
"yolo": "yarr"
12161216
]
1217-
let query = GameScore.query("yolo" == "yarr")
1217+
let query = GameScore.query(
1218+
equalToNoComparator(
1219+
key: "yolo",
1220+
value: "yarr"
1221+
)
1222+
)
12181223
let queryWhere = query.`where`
12191224

12201225
do {
@@ -1234,8 +1239,13 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12341239
XCTAssertThrowsError(try GameScore.query("yolo" == compareObject))
12351240
}
12361241

1237-
func testWhereKeyEqualToBool() throws {
1238-
let query = GameScore.query("isCounts" == true)
1242+
func testWhereKeyEqualToBoolNoComparator() throws {
1243+
let query = GameScore.query(
1244+
equalToNoComparator(
1245+
key: "isCounts",
1246+
value: true
1247+
)
1248+
)
12391249
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"isCounts\":true}}"
12401250
XCTAssertEqual(query.debugDescription, expected)
12411251
XCTAssertEqual(query.description, expected)
@@ -1245,7 +1255,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12451255
}
12461256

12471257
func testWhereKeyEqualToBoolEQ() throws {
1248-
let query = GameScore.query(equalTo(key: "isCounts", value: true, usingEqComparator: true))
1258+
let query = GameScore.query("isCounts" == true)
12491259
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"isCounts\":{\"$eq\":true}}}"
12501260
XCTAssertEqual(query.debugDescription, expected)
12511261
XCTAssertEqual(query.description, expected)
@@ -1254,10 +1264,15 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12541264
XCTAssertEqual(query, decoded)
12551265
}
12561266

1257-
func testWhereKeyEqualToParseObject() throws {
1267+
func testWhereKeyEqualToParseObjectNoComparator() throws {
12581268
var compareObject = GameScore(points: 11)
12591269
compareObject.objectId = "hello"
1260-
let query = try GameScore.query("yolo" == compareObject)
1270+
let query = try GameScore.query(
1271+
equalToNoComparator(
1272+
key: "yolo",
1273+
object: compareObject
1274+
)
1275+
)
12611276
// swiftlint:disable:next line_length
12621277
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}"
12631278
XCTAssertEqual(query.debugDescription, expected)
@@ -1269,7 +1284,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12691284
func testWhereKeyEqualToParseObjectEQ() throws {
12701285
var compareObject = GameScore(points: 11)
12711286
compareObject.objectId = "hello"
1272-
let query = try GameScore.query(equalTo(key: "yolo", object: compareObject, usingEqComparator: true))
1287+
let query = try GameScore.query("yolo" == compareObject)
12731288
// swiftlint:disable:next line_length
12741289
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"$eq\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}"
12751290
XCTAssertEqual(query.debugDescription, expected)
@@ -1281,10 +1296,12 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12811296
func testWhereKeyEqualToParseObjectDuplicateConstraint() throws {
12821297
var compareObject = GameScore(points: 11)
12831298
compareObject.objectId = "hello"
1284-
let query = try GameScore.query("yolo" == compareObject,
1285-
"yolo" == compareObject)
1299+
let query = try GameScore.query(
1300+
"yolo" == compareObject,
1301+
"yolo" == compareObject
1302+
)
12861303
// swiftlint:disable:next line_length
1287-
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}"
1304+
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"$eq\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}"
12881305
XCTAssertEqual(query.debugDescription, expected)
12891306
let encoded = try ParseCoding.jsonEncoder().encode(query)
12901307
let decoded = try ParseCoding.jsonDecoder().decode(Query<GameScore>.self, from: encoded)
@@ -1297,7 +1314,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
12971314
let pointer = try compareObject.toPointer()
12981315
let query = GameScore.query("yolo" == pointer)
12991316
// swiftlint:disable:next line_length
1300-
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}"
1317+
let expected = "{\"_method\":\"GET\",\"limit\":100,\"skip\":0,\"where\":{\"yolo\":{\"$eq\":{\"__type\":\"Pointer\",\"className\":\"GameScore\",\"objectId\":\"hello\"}}}}"
13011318
XCTAssertEqual(query.debugDescription, expected)
13021319
let encoded = try ParseCoding.jsonEncoder().encode(query)
13031320
let decoded = try ParseCoding.jsonDecoder().decode(Query<GameScore>.self, from: encoded)

0 commit comments

Comments
 (0)