Skip to content

Commit a15114b

Browse files
authored
refactor: make variadic call array counterparts (#301)
1 parent 5d2a370 commit a15114b

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

Sources/ParseSwift/Types/ParsePolygon.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct ParsePolygon: Codable, Hashable {
2222

2323
/**
2424
Create new `ParsePolygon` instance with coordinates.
25-
- parameter coordinates: The geopoints that make the polygon.
25+
- parameter coordinates: An array of geopoints that make the polygon.
2626
- throws: An error of type `ParseError`.
2727
*/
2828
public init(_ coordinates: [ParseGeoPoint]) throws {
@@ -36,8 +36,7 @@ public struct ParsePolygon: Codable, Hashable {
3636
- throws: An error of type `ParseError`.
3737
*/
3838
public init(_ coordinates: ParseGeoPoint...) throws {
39-
self.coordinates = coordinates
40-
try validate()
39+
try self.init(coordinates)
4140
}
4241

4342
func validate() throws {

Sources/ParseSwift/Types/Query.swift

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
125125
- parameter constraints: A variadic amount of zero or more `QueryConstraint`'s.
126126
*/
127127
public func `where`(_ constraints: QueryConstraint...) -> Query<T> {
128+
self.`where`(constraints)
129+
}
130+
131+
/**
132+
Add an array of variadic constraints.
133+
- parameter constraints: An array of zero or more `QueryConstraint`'s.
134+
*/
135+
public func `where`(_ constraints: [QueryConstraint]) -> Query<T> {
128136
var mutableQuery = self
129137
constraints.forEach({ mutableQuery.where.add($0) })
130138
return mutableQuery
@@ -186,13 +194,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
186194
- parameter keys: A variadic list of keys to load child `ParseObject`s for.
187195
*/
188196
public func include(_ keys: String...) -> Query<T> {
189-
var mutableQuery = self
190-
if mutableQuery.include != nil {
191-
mutableQuery.include = mutableQuery.include?.union(keys)
192-
} else {
193-
mutableQuery.include = Set(keys)
194-
}
195-
return mutableQuery
197+
self.include(keys)
196198
}
197199

198200
/**
@@ -227,13 +229,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
227229
- warning: Requires Parse Server 5.0.0+.
228230
*/
229231
public func exclude(_ keys: String...) -> Query<T> {
230-
var mutableQuery = self
231-
if mutableQuery.excludeKeys != nil {
232-
mutableQuery.excludeKeys = mutableQuery.excludeKeys?.union(keys)
233-
} else {
234-
mutableQuery.excludeKeys = Set(keys)
235-
}
236-
return mutableQuery
232+
self.exclude(keys)
237233
}
238234

239235
/**
@@ -259,13 +255,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
259255
- warning: Requires Parse Server 5.0.0+.
260256
*/
261257
public func select(_ keys: String...) -> Query<T> {
262-
var mutableQuery = self
263-
if mutableQuery.keys != nil {
264-
mutableQuery.keys = mutableQuery.keys?.union(keys)
265-
} else {
266-
mutableQuery.keys = Set(keys)
267-
}
268-
return mutableQuery
258+
self.select(keys)
269259
}
270260

271261
/**
@@ -306,13 +296,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
306296
- parameter keys: A variadic list of fields to receive back instead of the whole `ParseObject`.
307297
*/
308298
public func fields(_ keys: String...) -> Query<T> {
309-
var mutableQuery = self
310-
if mutableQuery.fields != nil {
311-
mutableQuery.fields = mutableQuery.fields?.union(keys)
312-
} else {
313-
mutableQuery.fields = Set(keys)
314-
}
315-
return mutableQuery
299+
self.fields(keys)
316300
}
317301

318302
/**
@@ -1128,7 +1112,7 @@ public extension ParseObject {
11281112
- returns: An instance of query for easy chaining.
11291113
*/
11301114
static func query(_ constraints: QueryConstraint...) -> Query<Self> {
1131-
Query<Self>(constraints)
1115+
Self.query(constraints)
11321116
}
11331117

11341118
/**

0 commit comments

Comments
 (0)