Skip to content

Commit 685f07a

Browse files
authored
Add example of customObjectId fetching an objectId which isn't saved (#154)
1 parent 6ecbd2b commit 685f07a

File tree

1 file changed

+12
-6
lines changed
  • ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage

1 file changed

+12
-6
lines changed

ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ struct GameScore: ParseObject {
3636
self.objectId = objectId
3737
self.score = score
3838
}
39+
40+
init(objectId: String) {
41+
self.objectId = objectId
42+
}
3943
}
4044

4145
//: Define initial GameScore this time with custom `objectId`.
@@ -101,14 +105,16 @@ query.first { result in
101105
}
102106
}
103107

104-
//: Query object
105-
let query = GameScore.query("objectId" == "myObjectId")
106-
query.find { result in
108+
//: Now we will attempt to fetch a ParseObject that isn't saved.
109+
let scoreToFetch = GameScore(objectId: "hello")
110+
111+
//: Asynchronously (preferred way) fetch this GameScore based on it's objectId alone.
112+
scoreToFetch.fetch { result in
107113
switch result {
108-
case .success(let found):
109-
print(found)
114+
case .success(let fetchedScore):
115+
print("Successfully fetched: \(fetchedScore)")
110116
case .failure(let error):
111-
print(error)
117+
assertionFailure("Error fetching: \(error)")
112118
}
113119
}
114120

0 commit comments

Comments
 (0)