Skip to content

Commit 04d74db

Browse files
committed
update docs
1 parent d7ba63e commit 04d74db

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

ParseSwift.playground/Pages/13 - Operations.xcplaygroundpage/Contents.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,22 @@ do {
7272
print(error)
7373
}
7474

75-
//: Query all scores who have a name.
75+
//: Query all scores whose is null or undefined.
7676
let query1 = GameScore.query(notNull(key: "name"))
7777
let results1 = try query1.find()
78+
print("Total found: \(results1.count)")
7879
results1.forEach { score in
7980
print("Found score with a name: \(score)")
8081
}
8182

83+
//: Query all scores whose name is undefined.
84+
let query2 = GameScore.query(exists(key: "name"))
85+
let results2 = try query2.find()
86+
print("Total found: \(results2.count)")
87+
results2.forEach { score in
88+
print("Found score with a name: \(score)")
89+
}
90+
8291
//: You can also remove a value for a property using unset.
8392
let unsetOperation = savedScore
8493
.operation.unset(("points", \.points))
@@ -100,13 +109,22 @@ do {
100109
print(error)
101110
}
102111

103-
//: Query synchronously (not preferred - all operations on main queue).
104-
let query2 = GameScore.query(isNull(key: "name"))
105-
let results2 = try query2.find()
106-
results2.forEach { score in
112+
//: Query all scores whose name is null or undefined.
113+
let query3 = GameScore.query(isNull(key: "name"))
114+
let results3 = try query3.find()
115+
print("Total found: \(results3.count)")
116+
results3.forEach { score in
107117
print("Found score with name is null: \(score)")
108118
}
109119

120+
//: Query all scores whose name is undefined.
121+
let query4 = GameScore.query(doesNotExist(key: "name"))
122+
let results4 = try query4.find()
123+
print("Total found: \(results4.count)")
124+
results4.forEach { score in
125+
print("Found score with name does not exist: \(score)")
126+
}
127+
110128
//: There are other operations: set/forceSet/unset/add/remove, etc. objects from `ParseObject`s.
111129
//: In fact, the `users` and `roles` relations from `ParseRoles` used the add/remove operations.
112130
//: Multiple operations can be chained together. See:

ParseSwift.playground/Pages/7 - GeoPoint.xcplaygroundpage/Contents.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ query2.find { results in
136136
}
137137
}
138138

139-
//: If you want to query for points > 50 and don't have a `ParseGeoPoint`.
139+
//: If you want to query for points > 50 and whose location is undefined.
140140
var query3 = GameScore.query("points" > 50, doesNotExist(key: "location"))
141141
query3.find { results in
142142
switch results {
@@ -154,7 +154,7 @@ query3.find { results in
154154
}
155155
}
156156

157-
//: Get the same results as the previous query using `isNull`.
157+
//: If you want to query for points > 50 and whose location is null or undefined.
158158
var anotherQuery3 = GameScore.query("points" > 50, isNull(key: "location"))
159159
anotherQuery3.find { results in
160160
switch results {
@@ -172,7 +172,7 @@ anotherQuery3.find { results in
172172
}
173173
}
174174

175-
//: If you want to query for points > 9 and have a `ParseGeoPoint`.
175+
//: If you want to query for points > 9 and whose location is not undefined.
176176
var query4 = GameScore.query("points" > 9, exists(key: "location"))
177177
query4.find { results in
178178
switch results {
@@ -191,7 +191,7 @@ query4.find { results in
191191
}
192192
}
193193

194-
//: Get the same results as the previous query using `notNull`.
194+
//: Get the same results as the previous query whose location is not null or undefined.
195195
var anotherQuery4 = GameScore.query("points" > 9, notNull(key: "location"))
196196
anotherQuery4.find { results in
197197
switch results {

Sources/ParseSwift/Types/QueryConstraint.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,6 @@ public func != <T>(key: String, value: T) throws -> QueryConstraint where T: Par
172172
try QueryConstraint(key: key, value: value.toPointer(), comparator: .notEqualTo)
173173
}
174174

175-
/**
176-
Add a constraint that requires that a key is equal to **null**.
177-
- parameter key: The key that the value is stored in.
178-
- returns: The same instance of `QueryConstraint` as the receiver.
179-
*/
180-
public func isNull (key: String) -> QueryConstraint {
181-
QueryConstraint(key: key, isNull: true)
182-
}
183-
184-
/**
185-
Add a constraint that requires that a key is not equal to **null**.
186-
- parameter key: The key that the value is stored in.
187-
- returns: The same instance of `QueryConstraint` as the receiver.
188-
*/
189-
public func notNull (key: String) -> QueryConstraint {
190-
QueryConstraint(key: key, comparator: .notEqualTo, isNull: true)
191-
}
192-
193175
internal struct InQuery<T>: Encodable where T: ParseObject {
194176
let query: Query<T>
195177
var className: String {
@@ -708,7 +690,25 @@ public func hasSuffix(key: String, suffix: String, modifiers: String? = nil) ->
708690
}
709691

710692
/**
711-
Add a constraint that requires a particular key exists.
693+
Add a constraint that requires that a key is equal to **null** or **undefined**.
694+
- parameter key: The key that the value is stored in.
695+
- returns: The same instance of `QueryConstraint` as the receiver.
696+
*/
697+
public func isNull (key: String) -> QueryConstraint {
698+
QueryConstraint(key: key, isNull: true)
699+
}
700+
701+
/**
702+
Add a constraint that requires that a key is not equal to **null** or **undefined**.
703+
- parameter key: The key that the value is stored in.
704+
- returns: The same instance of `QueryConstraint` as the receiver.
705+
*/
706+
public func notNull (key: String) -> QueryConstraint {
707+
QueryConstraint(key: key, comparator: .notEqualTo, isNull: true)
708+
}
709+
710+
/**
711+
Add a constraint that requires a particular key to be equal to **undefined**.
712712
- parameter key: The key that should exist.
713713
- returns: The resulting `QueryConstraint`.
714714
*/
@@ -717,7 +717,7 @@ public func exists(key: String) -> QueryConstraint {
717717
}
718718

719719
/**
720-
Add a constraint that requires a key not exist.
720+
Add a constraint that requires a key to not be equal to **undefined**.
721721
- parameter key: The key that should not exist.
722722
- returns: The resulting `QueryConstraint`.
723723
*/

0 commit comments

Comments
 (0)