Skip to content

feat: Add emptyObject property for sending modified keys to server #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Parse-Swift Changelog

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

### 1.10.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.9...1.10.0)

__Improvements__
- (Breaking Change) Provide ParseObject property, emptyObject, that makes it easy to send only modified keys to the server. This change "might" be breaking depending on your implementation as it requires ParseObjects to now have an empty initializer, init() ([#243](https://github.com/parse-community/Parse-Swift/pull/243)), thanks to [Corey Baker](https://github.com/cbaker6).

__Fixes__
- ParseUser shouldn't send email if it hasn't been modified or else email verification is resent ([#241](https://github.com/parse-community/Parse-Swift/pull/241)), thanks to [Corey Baker](https://github.com/cbaker6).

### 1.9.10
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.9...1.9.10)

__Fixes__
- ParseInstallation can't be retreived from Keychain after the first fun ([#236](https://github.com/parse-community/Parse-Swift/pull/236)), thanks to [Corey Baker](https://github.com/cbaker6).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ struct GameScore: ParseObject {

//: Your own properties.
var score: Int = 0
}

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

//: Custom initializer.
init(score: Int) {
self.score = score
}
Expand All @@ -62,6 +66,11 @@ struct GameData: ParseObject {
//: `ParseBytes` needs to be a part of the original schema
//: or else you will need your masterKey to force an upgrade.
var bytes: ParseBytes?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameData {

init (bytes: ParseBytes?, polygon: ParsePolygon) {
self.bytes = bytes
Expand All @@ -87,9 +96,11 @@ score.save { result in
assert(savedScore.score == 10)

/*: To modify, need to make it a var as the value type
was initialized as immutable.
was initialized as immutable. Using `emptyObject`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
var changedScore = savedScore
var changedScore = savedScore.emptyObject
changedScore.score = 200
changedScore.save { result in
switch result {
Expand Down Expand Up @@ -177,9 +188,11 @@ assert(savedScore?.updatedAt != nil)
assert(savedScore?.score == 10)

/*: To modify, need to make it a var as the value type
was initialized as immutable.
was initialized as immutable. Using `emptyObject`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
guard var changedScore = savedScore else {
guard var changedScore = savedScore?.emptyObject else {
fatalError()
}
changedScore.score = 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ struct GameScore: ParseObject {

//: Your own properties.
var score: Int = 0
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ struct GameScore: ParseObject {
var score: Int = 0
var location: ParseGeoPoint?
var name: String?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(name: String, score: Int) {
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ struct GameScore: ParseObject {

//: Your own properties.
var score: Int = 0
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ struct GameScore: ParseObject {

//: Your own properties.
var score: Int = 0
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(objectId: String, score: Int) {
self.objectId = objectId
Expand Down Expand Up @@ -64,9 +68,11 @@ score.save { result in
print("Saved score: \(savedScore)")

/*: To modify, need to make it a var as the value type
was initialized as immutable.
was initialized as immutable. Using `emptyObject`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
var changedScore = savedScore
var changedScore = savedScore.emptyObject
changedScore.score = 200
changedScore.save { result in
switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ struct GameScore: ParseObject, Identifiable {
var location: ParseGeoPoint?
var name: String?
var myFiles: [ParseFile]?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(name: String, score: Int) {
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ struct GameScore: ParseObject, Identifiable {
var score: Int = 0
var location: ParseGeoPoint?
var name: String?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(name: String, score: Int) {
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ struct GameScore: ParseObject {
var score: Int = 0
var location: ParseGeoPoint?
var name: String?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(name: String, score: Int) {
self.name = name
Expand Down Expand Up @@ -75,9 +79,7 @@ struct ContentView: View {
Text("Not subscribed to a query")
}

Spacer()

Text("Update GameScore in Parse Dashboard to see changes here")
Text("Update GameScore in Parse Dashboard to see changes here:")

Button(action: {
try? query.unsubscribe()
Expand All @@ -88,8 +90,8 @@ struct ContentView: View {
.foregroundColor(.white)
.padding()
.cornerRadius(20.0)
.frame(width: 300, height: 50)
})
Spacer()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ struct User: ParseUser {
var score: GameScore?
var targetScore: GameScore?
var allScores: [GameScore]?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension User {
//: Custom init for signup.
init(username: String, password: String, email: String) {
self.username = username
Expand All @@ -51,7 +55,11 @@ struct GameScore: ParseObject {

//: Your own properties.
var score: Int? = 0
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
Expand Down Expand Up @@ -95,12 +103,15 @@ User.login(username: "hello", password: "world") { result in
Asynchrounously - Performs work on background
queue and returns to specified callbackQueue.
If no callbackQueue is specified it returns to main queue.
Using `emptyObject` allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
User.current?.customKey = "myCustom"
User.current?.score = GameScore(score: 12)
User.current?.targetScore = GameScore(score: 100)
User.current?.allScores = [GameScore(score: 5), GameScore(score: 8)]
User.current?.save { result in
var currentUser = User.current?.emptyObject
currentUser?.customKey = "myCustom"
currentUser?.score = GameScore(score: 12)
currentUser?.targetScore = GameScore(score: 100)
currentUser?.allScores = [GameScore(score: 5), GameScore(score: 8)]
currentUser?.save { result in

switch result {
case .success(let updatedUser):
Expand Down Expand Up @@ -145,7 +156,7 @@ do {
//: you should create an instance of your user first.
var newUser = User(username: "parse", password: "aPassword*", email: "[email protected]")
//: Add any other additional information.
newUser.targetScore = .init(score: 40)
newUser.customKey = "mind"
newUser.signup { result in

switch result {
Expand Down Expand Up @@ -199,9 +210,10 @@ User.anonymous.login { result in
}

//: Convert the anonymous user to a real new user.
User.current?.username = "bye"
User.current?.password = "world"
User.current?.signup { result in
var currentUser2 = User.current?.emptyObject
currentUser2?.username = "bye"
currentUser2?.password = "world"
currentUser2?.signup { result in
switch result {

case .success(let user):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ struct GameScore: ParseObject {
//: Your own properties
var score: Int

//: a custom initializer
init() {
self.score = 0
}
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ struct Installation: ParseInstallation {
designated callbackQueue. If no callbackQueue is specified it
returns to main queue.
*/
Installation.current?.customKey = "myCustomInstallationKey2"
Installation.current?.save { results in
var currentInstallation = Installation.current
currentInstallation?.customKey = "myCustomInstallationKey2"
currentInstallation?.save { results in

switch results {
case .success(let updatedInstallation):
Expand All @@ -56,10 +57,13 @@ Installation.current?.save { results in
/*: Update your `ParseInstallation` `customKey` value.
Performs work on background queue and returns to designated on
designated callbackQueue. If no callbackQueue is specified it
returns to main queue.
returns to main queue. Using `emptyObject` allows you to only
send the updated keys to the parse server as opposed to the
whole object.
*/
Installation.current?.customKey = "updatedValue"
Installation.current?.save { results in
currentInstallation = currentInstallation?.emptyObject
currentInstallation?.customKey = "updatedValue"
currentInstallation?.save { results in

switch results {
case .success(let updatedInstallation):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ struct GameScore: ParseObject {
var updatedAt: Date?
var ACL: ParseACL?
var location: ParseGeoPoint?

//: Your own properties
var score: Int?
}

//: A custom initializer.
//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ struct Book: ParseObject {

//: Your own properties.
var title: String?
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension Book {

init(title: String) {
self.title = title
Expand All @@ -42,6 +47,15 @@ struct Author: ParseObject {
var book: Book
var otherBooks: [Book]?

init() {
self.name = "hello"
self.book = Book()
}
}

//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension Author {
init(name: String, book: Book) {
self.name = name
self.book = book
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ struct GameScore: ParseObject {
var score: Int = 0
var profilePicture: ParseFile?
var myData: ParseFile?
}

//custom initializer
//: It's recommended to place custom initializers in an extension
//: to preserve the convenience initializer.
extension GameScore {
//: Custom initializer.
init(score: Int) {
self.score = score
}
Expand Down
Loading