Skip to content

Commit

Permalink
docs: improve organization of SDK config (#409)
Browse files Browse the repository at this point in the history
* docs: improve organization of SDK config

* update playgrounds
  • Loading branch information
cbaker6 authored Sep 12, 2022
1 parent 62553bc commit 378b81a
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down Expand Up @@ -79,7 +82,10 @@ struct GameData: ParseObject {
//: or else you will need your masterKey to force an upgrade.
var bytes: ParseBytes?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if shouldRestoreKey(\.polygon,
Expand Down Expand Up @@ -120,10 +126,13 @@ score.save { result in
assert(savedScore.updatedAt != nil)
assert(savedScore.points == 10)

/*: To modify, need to make it a var as the value type
was initialized as immutable. Using `mergeable`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
/*:
To modify, you need to make it a var as the value type
was initialized as immutable. Using `mergeable`
allows you to only send the updated keys to the
parse server as opposed to the whole object. Make sure
to call `mergeable` before you begin
your first mutation of your `ParseObject`.
*/
var changedScore = savedScore.mergeable
changedScore.points = 200
Expand Down Expand Up @@ -210,15 +219,18 @@ assert(savedScore?.createdAt != nil)
assert(savedScore?.updatedAt != nil)
assert(savedScore?.points == 10)

/*: To modify, need to make it a var as the value type
was initialized as immutable. Using `mergeable`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
/*:
To modify, you need to make a mutable copy of `savedScore`.
Instead of using `mergeable` this time, we will use the `set()`
method which allows us to accomplish the same thing
as `mergeable`. You can choose to use `set()` or
`mergeable` as long as you use either before you begin
your first mutation of your `ParseObject`.
*/
guard var changedScore = savedScore?.mergeable else {
guard var changedScore = savedScore else {
fatalError("Should have produced mutable changedScore")
}
changedScore.points = 200
changedScore = changedScore.set(\.points, to: 200)

let savedChangedScore: GameScore?
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ struct GameScore: ParseObject {
var location: ParseGeoPoint?
var name: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ struct User: ParseUser {
var customKey: String?
var scores: ParseRelation<Self>?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand All @@ -55,7 +58,10 @@ struct Role<RoleUser: ParseUser>: ParseRole {
//: Provided by Role.
var name: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.name,
Expand All @@ -78,7 +84,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ struct GameScore: ParseObject {
var points: Int?
var name: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down Expand Up @@ -79,10 +82,11 @@ score.save { result in
//: Any changes to `createdAt` and `objectId` will not be saved to the server.
print("Saved score: \(savedScore)")

/*: To modify, need to make it a var as the value type
was initialized as immutable. Using `.mergeable`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
/*:
To modify, need to make it a var as the value type
was initialized as immutable. Using `.mergeable` or `set()`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
var changedScore = savedScore.mergeable
changedScore.points = 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ struct GameScore: ParseObject {
var name: String?
var myFiles: [ParseFile]?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ struct GameScore: ParseObject {
var location: ParseGeoPoint?
var name: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ struct GameScore: ParseObject {
var location: ParseGeoPoint?
var name: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct GameScore: ParseObject {
var oldScore: Int?
var isHighest: Bool?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ struct User: ParseUser {
//: Your custom keys.
var customKey: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand All @@ -59,7 +62,10 @@ struct GameScore2: ParseObject {
var owner: User?
var rivals: [User]?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ struct Installation: ParseInstallation {
//: Your custom keys
var customKey: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ struct User: ParseUser {
//: Your custom keys.
var customKey: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct User: ParseUser {
var targetScore: GameScore?
var allScores: [GameScore]?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand Down Expand Up @@ -80,7 +83,10 @@ struct GameScore: ParseObject {
//: Your own properties.
var points: Int? = 0

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down Expand Up @@ -112,9 +118,10 @@ do {
print("Error logging out: \(error)")
}

/*: Login - asynchronously - Performs work on background
queue and returns to specified callbackQueue.
If no callbackQueue is specified it returns to main queue.
/*:
Login - asynchronously - Performs work on background
queue and returns to specified callbackQueue.
If no callbackQueue is specified it returns to main queue.
*/
User.login(username: "hello", password: "world") { result in

Expand All @@ -133,17 +140,21 @@ User.login(username: "hello", password: "world") { result in
}
}

/*: Save your first `customKey` value to your `ParseUser`
Asynchrounously - Performs work on background
queue and returns to specified callbackQueue.
If no callbackQueue is specified it returns to main queue.
Using `.mergeable` allows you to only send the updated keys to the
parse server as opposed to the whole object.
/*:
Save your first `customKey` value to your `ParseUser`
Asynchrounously - Performs work on background
queue and returns to specified callbackQueue.
If no callbackQueue is specified it returns to main queue.
Using `.mergeable` or `set()` allows you to only send
the updated keys to the parse server as opposed to the
whole object. You can chain set calls or even use
`set()` in combination with mutating the `ParseObject`
directly.
*/
var currentUser = User.current?.mergeable
currentUser?.customKey = "myCustom"
currentUser?.gameScore = GameScore(points: 12)
currentUser?.targetScore = GameScore(points: 100)
var currentUser = User.current?
.set(\.customKey, to: "myCustom")
.set(\.gameScore, to: GameScore(points: 12))
.set(\.targetScore, to: GameScore(points: 100))
currentUser?.allScores = [GameScore(points: 5), GameScore(points: 8)]
currentUser?.save { result in

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct GameScore: ParseObject {
//: Your own properties
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ struct Installation: ParseInstallation {
//: Your custom keys
var customKey: String?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.customKey,
Expand Down Expand Up @@ -65,10 +68,13 @@ currentInstallation?.save { results in
}
}

/*: Update your `ParseInstallation` `customKey` and `channels` values.
Performs work on background queue and returns to designated on
designated callbackQueue. If no callbackQueue is specified it
returns to main queue.
/*:
Update your `ParseInstallation` `customKey` and `channels` values.
Performs work on background queue and returns to designated on
designated callbackQueue. If no callbackQueue is specified it
returns to main queue. Using `.mergeable` or `set()`
allows you to only send the updated keys to the
parse server as opposed to the whole object.
*/
var installationToUpdate = Installation.current?.mergeable
installationToUpdate?.customKey = "myCustomInstallationKey2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct GameScore: ParseObject {
//: Your own properties
var points: Int?

//: Implement your own version of merge
/*:
Optional - implement your own version of merge
for faster decoding after updating your `ParseObject`.
*/
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.points,
Expand Down
Loading

0 comments on commit 378b81a

Please sign in to comment.