Skip to content

Commit 3bf2471

Browse files
authored
feat: add score property, withCount, and matchesText options (#306)
* feat: add score property, withCount, and matchesText options * increase codecov * add change log * Playground nits
1 parent aa8b027 commit 3bf2471

File tree

81 files changed

+1459
-718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1459
-718
lines changed

CHANGELOG.md

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

33
### main
44

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

8+
### 3.0.0
9+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.5.1...3.0.0)
10+
11+
__Improvements__
12+
- (Breaking Change) Adds options to matchesText query constraint along with the ability to see matching score. The compiler should recommend the new score property to all ParseObjects ([#306](https://github.com/parse-community/Parse-Swift/pull/306)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
- Adds withCount query ([#306](https://github.com/parse-community/Parse-Swift/pull/306)), thanks to [Corey Baker](https://github.com/cbaker6).
14+
815
### 2.5.1
916
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.5.0...2.5.1)
1017

ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ struct GameScore: ParseObject, ParseObjectMutable {
3636
var createdAt: Date?
3737
var updatedAt: Date?
3838
var ACL: ParseACL?
39+
var score: Double?
3940

4041
//: Your own properties.
41-
var score: Int = 0
42+
var points: Int = 0
4243
}
4344

4445
//: It's recommended to place custom initializers in an extension
4546
//: to preserve the convenience initializer.
4647
extension GameScore {
4748

48-
init(score: Int) {
49-
self.score = score
49+
init(points: Int) {
50+
self.points = points
5051
}
5152

5253
init(objectId: String?) {
@@ -60,6 +61,7 @@ struct GameData: ParseObject {
6061
var createdAt: Date?
6162
var updatedAt: Date?
6263
var ACL: ParseACL?
64+
var score: Double?
6365

6466
//: Your own properties.
6567
var polygon: ParsePolygon?
@@ -79,8 +81,8 @@ extension GameData {
7981
}
8082

8183
//: Define initial GameScores.
82-
let score = GameScore(score: 10)
83-
let score2 = GameScore(score: 3)
84+
let score = GameScore(points: 10)
85+
let score2 = GameScore(points: 3)
8486

8587
/*: Save asynchronously (preferred way) - Performs work on background
8688
queue and returns to specified callbackQueue.
@@ -92,25 +94,25 @@ score.save { result in
9294
assert(savedScore.objectId != nil)
9395
assert(savedScore.createdAt != nil)
9496
assert(savedScore.updatedAt != nil)
95-
assert(savedScore.score == 10)
97+
assert(savedScore.points == 10)
9698

9799
/*: To modify, need to make it a var as the value type
98100
was initialized as immutable. Using `mutable`
99101
allows you to only send the updated keys to the
100102
parse server as opposed to the whole object.
101103
*/
102104
var changedScore = savedScore.mutable
103-
changedScore.score = 200
105+
changedScore.points = 200
104106
changedScore.save { result in
105107
switch result {
106108
case .success(var savedChangedScore):
107-
assert(savedChangedScore.score == 200)
109+
assert(savedChangedScore.points == 200)
108110
assert(savedScore.objectId == savedChangedScore.objectId)
109111

110112
/*: Note that savedChangedScore is mutable since it's
111113
a var after success.
112114
*/
113-
savedChangedScore.score = 500
115+
savedChangedScore.points = 500
114116

115117
case .failure(let error):
116118
assertionFailure("Error saving: \(error)")
@@ -132,7 +134,7 @@ var score2ForFetchedLater: GameScore?
132134
otherResults.forEach { otherResult in
133135
switch otherResult {
134136
case .success(let savedScore):
135-
print("Saved \"\(savedScore.className)\" with score \(savedScore.score) successfully")
137+
print("Saved \"\(savedScore.className)\" with points \(savedScore.points) successfully")
136138
if index == 1 {
137139
score2ForFetchedLater = savedScore
138140
}
@@ -148,15 +150,15 @@ var score2ForFetchedLater: GameScore?
148150
}
149151

150152
//: Saving multiple GameScores at once using a transaction.
151-
//: Currently doesn't work on mongo
153+
//: May not work on MongoDB depending on your configuration.
152154
/*[score, score2].saveAll(transaction: true) { results in
153155
switch results {
154156
case .success(let otherResults):
155157
var index = 0
156158
otherResults.forEach { otherResult in
157159
switch otherResult {
158160
case .success(let savedScore):
159-
print("Saved \"\(savedScore.className)\" with score \(savedScore.score) successfully")
161+
print("Saved \"\(savedScore.className)\" with points \(savedScore.points) successfully")
160162
if index == 1 {
161163
score2ForFetchedLater = savedScore
162164
}
@@ -184,7 +186,7 @@ assert(savedScore != nil)
184186
assert(savedScore?.objectId != nil)
185187
assert(savedScore?.createdAt != nil)
186188
assert(savedScore?.updatedAt != nil)
187-
assert(savedScore?.score == 10)
189+
assert(savedScore?.points == 10)
188190

189191
/*: To modify, need to make it a var as the value type
190192
was initialized as immutable. Using `mutable`
@@ -194,7 +196,7 @@ assert(savedScore?.score == 10)
194196
guard var changedScore = savedScore?.mutable else {
195197
fatalError()
196198
}
197-
changedScore.score = 200
199+
changedScore.points = 200
198200

199201
let savedChangedScore: GameScore?
200202
do {
@@ -205,7 +207,7 @@ do {
205207
}
206208

207209
assert(savedChangedScore != nil)
208-
assert(savedChangedScore!.score == 200)
210+
assert(savedChangedScore!.points == 200)
209211
assert(savedScore!.objectId == savedChangedScore!.objectId)
210212

211213
let otherResults: [(Result<GameScore, ParseError>)]?
@@ -220,14 +222,14 @@ assert(otherResults != nil)
220222
otherResults!.forEach { result in
221223
switch result {
222224
case .success(let savedScore):
223-
print("Saved \"\(savedScore.className)\" with score \(savedScore.score) successfully")
225+
print("Saved \"\(savedScore.className)\" with points \(savedScore.points) successfully")
224226
case .failure(let error):
225227
assertionFailure("Error saving: \(error)")
226228
}
227229
}
228230

229231
//: Now we will create another object and delete it.
230-
let score3 = GameScore(score: 30)
232+
let score3 = GameScore(points: 30)
231233

232234
//: Save the score and store it in "scoreToDelete".
233235
var scoreToDelete: GameScore!

ParseSwift.playground/Pages/10 - Cloud Code.xcplaygroundpage/Contents.swift

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,28 @@ PlaygroundPage.current.needsIndefiniteExecution = true
1414
initializeParse()
1515

1616
//: Create your own value typed `ParseCloud` type.
17-
struct Cloud: ParseCloud {
17+
struct Hello: ParseCloud {
1818

1919
//: Return type of your Cloud Function
2020
typealias ReturnType = String
2121

22-
//: These are required by `ParseCloud`
23-
var functionJobName: String
22+
//: These are required by `ParseCloud`, you can set the default value to make it easier
23+
//: to use.
24+
var functionJobName: String = "hello"
25+
26+
//: If your cloud function takes arguments, they can be passed by creating properties:
27+
//var argument1: [String: Int] = ["test": 5]
28+
}
29+
30+
//: Create another `ParseCloud` type.
31+
struct TestCloudCode: ParseCloud {
32+
33+
//: Return type of your Cloud Function
34+
typealias ReturnType = String
35+
36+
//: These are required by `ParseCloud`, you can set the default value to make it easier
37+
//: to use.
38+
var functionJobName: String = "testCloudCode"
2439

2540
//: If your cloud function takes arguments, they can be passed by creating properties:
2641
//var argument1: [String: Int] = ["test": 5]
@@ -32,9 +47,9 @@ struct Cloud: ParseCloud {
3247
return 'Hello world!';
3348
});
3449
*/
35-
let cloud = Cloud(functionJobName: "hello")
50+
let hello = Hello()
3651

37-
cloud.runFunction { result in
52+
hello.runFunction { result in
3853
switch result {
3954
case .success(let response):
4055
print("Response from cloud function: \(response)")
@@ -50,9 +65,9 @@ cloud.runFunction { result in
5065
throw new Parse.Error(3000, "cloud has an error on purpose.");
5166
});
5267
*/
53-
let cloudError = Cloud(functionJobName: "testCloudCode")
68+
let testCloudCode = TestCloudCode()
5469

55-
cloudError.runFunction { result in
70+
testCloudCode.runFunction { result in
5671
switch result {
5772
case .success:
5873
assertionFailure("Should have thrown a custom error")
@@ -91,17 +106,18 @@ struct GameScore: ParseObject {
91106
var createdAt: Date?
92107
var updatedAt: Date?
93108
var ACL: ParseACL?
109+
var score: Double?
94110

95111
//: Your own properties.
96-
var score: Int = 0
112+
var points: Int = 0
97113
}
98114

99115
//: It's recommended to place custom initializers in an extension
100116
//: to preserve the convenience initializer.
101117
extension GameScore {
102118
//: Custom initializer.
103-
init(score: Int) {
104-
self.score = score
119+
init(points: Int) {
120+
self.points = points
105121
}
106122

107123
init(objectId: String?) {
@@ -110,7 +126,7 @@ extension GameScore {
110126
}
111127

112128
//: Define a GameScore.
113-
let score = GameScore(score: 10)
129+
let score = GameScore(points: 10)
114130

115131
//: Save asynchronously (preferred way) with the context option.
116132
score.save(options: [.context(["hello": "world"])]) { result in

ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ struct GameScore: ParseObject {
1616
var createdAt: Date?
1717
var updatedAt: Date?
1818
var ACL: ParseACL?
19+
var score: Double?
1920

2021
//: Your own properties.
21-
var score: Int = 0
22+
var points: Int = 0
2223
var location: ParseGeoPoint?
2324
var name: String?
2425
}
@@ -27,9 +28,9 @@ struct GameScore: ParseObject {
2728
//: to preserve the convenience initializer.
2829
extension GameScore {
2930
//: Custom initializer.
30-
init(name: String, score: Int) {
31+
init(name: String, points: Int) {
3132
self.name = name
32-
self.score = score
33+
self.points = points
3334
}
3435
}
3536

@@ -54,7 +55,7 @@ if let socket = ParseLiveQuery.getDefault() {
5455
}
5556

5657
//: Create a query just as you normally would.
57-
var query = GameScore.query("score" < 11)
58+
var query = GameScore.query("points" < 11)
5859

5960
//: This is how you subscribe to your created query using callbacks.
6061
let subscription = query.subscribeCallback!
@@ -126,10 +127,10 @@ ParseLiveQuery.client?.sendPing { error in
126127
}
127128

128129
//: Create a new query.
129-
var query2 = GameScore.query("score" > 50)
130+
var query2 = GameScore.query("points" > 50)
130131

131132
//: Select the fields you are interested in receiving.
132-
query2.fields("score")
133+
query2.fields("points")
133134

134135
//: Subscribe to your new query.
135136
let subscription2 = query2.subscribeCallback!

ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct User: ParseUser {
1919
var createdAt: Date?
2020
var updatedAt: Date?
2121
var ACL: ParseACL?
22+
var score: Double?
2223

2324
//: These are required by `ParseUser`.
2425
var username: String?
@@ -38,6 +39,7 @@ struct Role<RoleUser: ParseUser>: ParseRole {
3839
var createdAt: Date?
3940
var updatedAt: Date?
4041
var ACL: ParseACL?
42+
var score: Double?
4143

4244
//: Provided by Role.
4345
var name: String
@@ -54,17 +56,18 @@ struct GameScore: ParseObject, ParseObjectMutable {
5456
var createdAt: Date?
5557
var updatedAt: Date?
5658
var ACL: ParseACL?
59+
var score: Double?
5760

5861
//: Your own properties.
59-
var score: Int = 0
62+
var points: Int = 0
6063
}
6164

6265
//: It's recommended to place custom initializers in an extension
6366
//: to preserve the convenience initializer.
6467
extension GameScore {
6568

66-
init(score: Int) {
67-
self.score = score
69+
init(points: Int) {
70+
self.points = points
6871
}
6972

7073
init(objectId: String?) {
@@ -248,8 +251,8 @@ do {
248251
//: All `ParseObject`s have a `ParseRelation` attribute that be used on instances.
249252
//: For example, the User has:
250253
var relation = User.current!.relation
251-
let score1 = GameScore(score: 53)
252-
let score2 = GameScore(score: 57)
254+
let score1 = GameScore(points: 53)
255+
let score2 = GameScore(points: 57)
253256

254257
//: Add new child relationships.
255258
[score1, score2].saveAll { result in
@@ -263,7 +266,7 @@ let score2 = GameScore(score: 57)
263266
switch result {
264267
case .success(let saved):
265268
print("The relation saved successfully: \(saved)")
266-
print("Check \"scores\" field in your \"_User\" class in Parse Dashboard.")
269+
print("Check \"pointss\" field in your \"_User\" class in Parse Dashboard.")
267270

268271
case .failure(let error):
269272
print("Error saving role: \(error)")

0 commit comments

Comments
 (0)