Skip to content

Add example of customObjectId fetching an objectId which isn't saved #154

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 1 commit into from
Jun 3, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ struct GameScore: ParseObject {
self.objectId = objectId
self.score = score
}

init(objectId: String) {
self.objectId = objectId
}
}

//: Define initial GameScore this time with custom `objectId`.
Expand Down Expand Up @@ -101,14 +105,16 @@ query.first { result in
}
}

//: Query object
let query = GameScore.query("objectId" == "myObjectId")
query.find { result in
//: Now we will attempt to fetch a ParseObject that isn't saved.
let scoreToFetch = GameScore(objectId: "hello")

//: Asynchronously (preferred way) fetch this GameScore based on it's objectId alone.
scoreToFetch.fetch { result in
switch result {
case .success(let found):
print(found)
case .success(let fetchedScore):
print("Successfully fetched: \(fetchedScore)")
case .failure(let error):
print(error)
assertionFailure("Error fetching: \(error)")
}
}

Expand Down