From 6b66f618451228fbf10e5712ff77d07fe11cbf31 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Sun, 12 Dec 2021 20:47:08 -0500 Subject: [PATCH] refactor: make variadic call array counterparts --- Sources/ParseSwift/Types/ParsePolygon.swift | 5 +-- Sources/ParseSwift/Types/Query.swift | 42 +++++++-------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Sources/ParseSwift/Types/ParsePolygon.swift b/Sources/ParseSwift/Types/ParsePolygon.swift index f1388ef00..d7464faa9 100644 --- a/Sources/ParseSwift/Types/ParsePolygon.swift +++ b/Sources/ParseSwift/Types/ParsePolygon.swift @@ -22,7 +22,7 @@ public struct ParsePolygon: Codable, Hashable { /** Create new `ParsePolygon` instance with coordinates. - - parameter coordinates: The geopoints that make the polygon. + - parameter coordinates: An array of geopoints that make the polygon. - throws: An error of type `ParseError`. */ public init(_ coordinates: [ParseGeoPoint]) throws { @@ -36,8 +36,7 @@ public struct ParsePolygon: Codable, Hashable { - throws: An error of type `ParseError`. */ public init(_ coordinates: ParseGeoPoint...) throws { - self.coordinates = coordinates - try validate() + try self.init(coordinates) } func validate() throws { diff --git a/Sources/ParseSwift/Types/Query.swift b/Sources/ParseSwift/Types/Query.swift index b2306702f..102944de7 100644 --- a/Sources/ParseSwift/Types/Query.swift +++ b/Sources/ParseSwift/Types/Query.swift @@ -125,6 +125,14 @@ public struct Query: Encodable, Equatable where T: ParseObject { - parameter constraints: A variadic amount of zero or more `QueryConstraint`'s. */ public func `where`(_ constraints: QueryConstraint...) -> Query { + self.`where`(constraints) + } + + /** + Add an array of variadic constraints. + - parameter constraints: An array of zero or more `QueryConstraint`'s. + */ + public func `where`(_ constraints: [QueryConstraint]) -> Query { var mutableQuery = self constraints.forEach({ mutableQuery.where.add($0) }) return mutableQuery @@ -186,13 +194,7 @@ public struct Query: Encodable, Equatable where T: ParseObject { - parameter keys: A variadic list of keys to load child `ParseObject`s for. */ public func include(_ keys: String...) -> Query { - var mutableQuery = self - if mutableQuery.include != nil { - mutableQuery.include = mutableQuery.include?.union(keys) - } else { - mutableQuery.include = Set(keys) - } - return mutableQuery + self.include(keys) } /** @@ -227,13 +229,7 @@ public struct Query: Encodable, Equatable where T: ParseObject { - warning: Requires Parse Server 5.0.0+. */ public func exclude(_ keys: String...) -> Query { - var mutableQuery = self - if mutableQuery.excludeKeys != nil { - mutableQuery.excludeKeys = mutableQuery.excludeKeys?.union(keys) - } else { - mutableQuery.excludeKeys = Set(keys) - } - return mutableQuery + self.exclude(keys) } /** @@ -259,13 +255,7 @@ public struct Query: Encodable, Equatable where T: ParseObject { - warning: Requires Parse Server 5.0.0+. */ public func select(_ keys: String...) -> Query { - var mutableQuery = self - if mutableQuery.keys != nil { - mutableQuery.keys = mutableQuery.keys?.union(keys) - } else { - mutableQuery.keys = Set(keys) - } - return mutableQuery + self.select(keys) } /** @@ -306,13 +296,7 @@ public struct Query: Encodable, Equatable where T: ParseObject { - parameter keys: A variadic list of fields to receive back instead of the whole `ParseObject`. */ public func fields(_ keys: String...) -> Query { - var mutableQuery = self - if mutableQuery.fields != nil { - mutableQuery.fields = mutableQuery.fields?.union(keys) - } else { - mutableQuery.fields = Set(keys) - } - return mutableQuery + self.fields(keys) } /** @@ -1128,7 +1112,7 @@ public extension ParseObject { - returns: An instance of query for easy chaining. */ static func query(_ constraints: QueryConstraint...) -> Query { - Query(constraints) + Self.query(constraints) } /**