Skip to content

Commit 4d2d509

Browse files
authored
feat: add variadic QueryConstraint methods (#345)
1 parent a34c5cb commit 4d2d509

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
### main
44

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

8+
### 4.2.0
9+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.1.0...4.2.0)
10+
11+
__New features__
12+
- Add variadic QueryConstraint methods for or, nor, and ([#345](https://github.com/parse-community/Parse-Swift/pull/345)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
__Improvements__
915
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to clientDefault ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).
1016

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

Sources/ParseSwift/Types/ParsePolygon.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct ParsePolygon: Codable, Hashable {
3232

3333
/**
3434
Create new `ParsePolygon` instance with a variadic amount of coordinates.
35-
- parameter coordinates: variadic amount of zero or more `ParseGeoPoint`'s.
35+
- parameter coordinates: variadic amount of zero or more `ParseGeoPoint`'s.
3636
- throws: An error of type `ParseError`.
3737
*/
3838
public init(_ coordinates: ParseGeoPoint...) throws {

Sources/ParseSwift/Types/QueryConstraint.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ public func or <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
273273
return QueryConstraint(key: QueryConstraint.Comparator.or.rawValue, value: orQueries)
274274
}
275275

276+
/**
277+
Returns a `Query` that is the `or` of the passed in queries.
278+
- parameter queries: The variadic amount of queries to `or` together.
279+
- returns: An instance of `QueryConstraint`'s that are the `or` of the passed in queries.
280+
*/
281+
public func or <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
282+
or(queries: queries)
283+
}
284+
276285
/**
277286
Returns a `Query` that is the `nor` of the passed in queries.
278287
- parameter queries: The list of queries to `nor` together.
@@ -283,12 +292,21 @@ public func nor <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
283292
return QueryConstraint(key: QueryConstraint.Comparator.nor.rawValue, value: orQueries)
284293
}
285294

295+
/**
296+
Returns a `Query` that is the `nor` of the passed in queries.
297+
- parameter queries: The variadic amount of queries to `nor` together.
298+
- returns: An instance of `QueryConstraint`'s that are the `nor` of the passed in queries.
299+
*/
300+
public func nor <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
301+
nor(queries: queries)
302+
}
303+
286304
/**
287305
Constructs a Query that is the `and` of the passed in queries.
288306

289307
For example:
290308

291-
var compoundQueryConstraints = and(query1, query2, query3)
309+
var compoundQueryConstraints = and([query1, query2, query3])
292310

293311
will create a compoundQuery that is an and of the query1, query2, and query3.
294312
- parameter queries: The list of queries to `and` together.
@@ -299,6 +317,21 @@ public func and <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
299317
return QueryConstraint(key: QueryConstraint.Comparator.and.rawValue, value: andQueries)
300318
}
301319

320+
/**
321+
Constructs a Query that is the `and` of the passed in queries.
322+
323+
For example:
324+
325+
var compoundQueryConstraints = and(query1, query2, query3)
326+
327+
will create a compoundQuery that is an and of the query1, query2, and query3.
328+
- parameter queries: The variadic amount of queries to `and` together.
329+
- returns: An instance of `QueryConstraint`'s that are the `and` of the passed in queries.
330+
*/
331+
public func and <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
332+
and(queries: queries)
333+
}
334+
302335
/**
303336
Add a constraint that requires that a key's value matches a `Query` constraint.
304337
- warning: This only works where the key's values are `ParseObject`s or arrays of `ParseObject`s.

Tests/ParseSwiftTests/ParseQueryTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
17411741
]
17421742
let query1 = GameScore.query("points" <= 50)
17431743
let query2 = GameScore.query("points" <= 200)
1744-
let constraint = or(queries: [query1, query2])
1744+
let constraint = or(queries: query1, query2)
17451745
let query = Query<GameScore>(constraint)
17461746
let queryWhere = query.`where`
17471747

@@ -1772,7 +1772,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
17721772
]
17731773
let query1 = GameScore.query("points" <= 50)
17741774
let query2 = GameScore.query("points" <= 200)
1775-
let constraint = nor(queries: [query1, query2])
1775+
let constraint = nor(queries: query1, query2)
17761776
let query = Query<GameScore>(constraint)
17771777
let queryWhere = query.`where`
17781778

@@ -1803,7 +1803,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
18031803
]
18041804
let query1 = GameScore.query("points" <= 50)
18051805
let query2 = GameScore.query("points" <= 200)
1806-
let constraint = and(queries: [query1, query2])
1806+
let constraint = and(queries: query1, query2)
18071807
let query = Query<GameScore>(constraint)
18081808
let queryWhere = query.`where`
18091809

0 commit comments

Comments
 (0)