Skip to content

Commit ed8dced

Browse files
committed
Make ParseLiveQuery.client public
1 parent 385ef3f commit ed8dced

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import PlaygroundSupport
1111
import Foundation
1212
import ParseSwift
13+
#if canImport(SwiftUI)
1314
import SwiftUI
15+
#if canImport(Combine)
16+
import Combine
17+
#endif
18+
#endif
1419
PlaygroundPage.current.needsIndefiniteExecution = true
1520

1621
initializeParse()
@@ -39,7 +44,8 @@ struct GameScore: ParseObject {
3944

4045
//: Create a query just as you normally would.
4146
var query = GameScore.query("score" > 9)
42-
47+
/*
48+
#if canImport(SwiftUI)
4349
//: To use subscriptions inside of SwiftUI
4450
struct ContentView: View {
4551

@@ -93,7 +99,8 @@ struct ContentView: View {
9399
}
94100

95101
PlaygroundPage.current.setLiveView(ContentView())
96-
102+
#endif
103+
*/
97104
//: This is how you subscribe to your created query using callbacks.
98105
let subscription = query.subscribeCallback!
99106

@@ -141,6 +148,21 @@ do {
141148
print(error)
142149
}
143150

151+
//: Ping the LiveQuery server
152+
ParseLiveQuery.client?.sendPing { error in
153+
if let error = error {
154+
print("Error pinging LiveQuery server: \(error)")
155+
} else {
156+
print("Successfully pinged server!")
157+
}
158+
}
159+
160+
//: To close the current LiveQuery connection.
161+
ParseLiveQuery.client?.close()
162+
163+
//: To close all LiveQuery connections.
164+
ParseLiveQuery.client?.closeAll()
165+
144166
//: Create a new query.
145167
var query2 = GameScore.query("score" > 50)
146168

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public final class ParseLiveQuery: NSObject {
213213
@available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *)
214214
extension ParseLiveQuery {
215215

216-
static var client = try? ParseLiveQuery()
216+
public private(set) static var client = try? ParseLiveQuery()
217217

218218
var reconnectInterval: Int {
219219
let min = NSDecimalNumber(decimal: Swift.min(30, pow(2, attempts) - 1))

0 commit comments

Comments
 (0)