Skip to content

Commit a82fd99

Browse files
authored
feat: allow LiveQuery client to be set using defaultClient property (#360)
1 parent 6d9acd6 commit a82fd99

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.4.0...main)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
__Improvements__
9+
- Allow LiveQuery client to be set using ParseLiveQuery.defaultClient and deprecate ParseLiveQuery.setDefault(). Show usage of deprecated code as warnings during compile time and suggest changes ([#360](https://github.com/parse-community/Parse-Swift/pull/360)), thanks to [Corey Baker](https://github.com/cbaker6).
10+
811
### 4.4.0
912
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.3.1...4.4.0)
1013

@@ -30,7 +33,7 @@ __New features__
3033
- Add variadic QueryConstraint methods for or, nor, and ([#345](https://github.com/parse-community/Parse-Swift/pull/345)), thanks to [Corey Baker](https://github.com/cbaker6).
3134

3235
__Improvements__
33-
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to clientDefault ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).
36+
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to defaultClient ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).
3437

3538
### 4.1.0
3639
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.0.1...4.1.0)

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Not attempting to open ParseLiveQuery socket anymore
211211
taskDelegate: self)
212212
self.resumeTask { _ in }
213213
if isDefault {
214-
Self.setDefault(self)
214+
Self.defaultClient = self
215215
}
216216
}
217217

@@ -268,19 +268,27 @@ extension ParseLiveQuery {
268268

269269
/// The default `ParseLiveQuery` client for all LiveQuery connections.
270270
class public var defaultClient: ParseLiveQuery? {
271-
Self.client
271+
get {
272+
Self.client
273+
}
274+
set {
275+
Self.client = nil
276+
Self.client = newValue
277+
}
272278
}
273279

274280
/// Set a specific ParseLiveQuery client to be the default for all `ParseLiveQuery` connections.
275281
/// - parameter client: The client to set as the default.
282+
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `defaultClient`.
283+
@available(*, deprecated, renamed: "defaultClient")
276284
class public func setDefault(_ client: ParseLiveQuery) {
277-
Self.client = nil
278-
Self.client = client
285+
Self.defaultClient = client
279286
}
280287

281288
/// Get the default `ParseLiveQuery` client for all LiveQuery connections.
282289
/// - returns: The default `ParseLiveQuery` client.
283-
/// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `defaultClient`.
290+
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `defaultClient`.
291+
@available(*, deprecated, renamed: "defaultClient")
284292
class public func getDefault() -> ParseLiveQuery? {
285293
Self.defaultClient
286294
}

Sources/ParseSwift/Objects/ParseSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public protocol ParseSession: ParseObject {
2929
/// Information about how the session was created.
3030
var createdWith: [String: String] { get }
3131

32-
/// Referrs to the `ParseInstallation` where the
32+
/// Refers to the `ParseInstallation` where the
3333
/// session logged in from.
3434
var installationId: String { get }
3535

Sources/ParseSwift/Types/ParseAnalytics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public struct ParseAnalytics: ParseType, Hashable {
2121

2222
/// Explicitly set the time associated with a given event. If not provided the server
2323
/// time will be used.
24-
/// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `date`.
24+
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `date`.
25+
@available(*, deprecated, renamed: "date")
2526
public var at: Date? { // swiftlint:disable:this identifier_name
2627
get {
2728
date

Tests/ParseSwiftTests/ParseAnalyticsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ParseAnalyticsTests: XCTestCase {
5454
XCTAssertEqual(command2.body?.at, date)
5555
XCTAssertNotNil(command2.body?.dimensions)
5656

57-
event2.at = nil //Clear date for comparison
57+
event2.date = nil //Clear date for comparison
5858
let decoded = event2.debugDescription
5959
let expected = "{\"dimensions\":{\"stop\":\"drop\"},\"name\":\"hello\"}"
6060
XCTAssertEqual(decoded, expected)

Tests/ParseSwiftTests/ParseLiveQueryAsyncTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ParseLiveQueryAsyncTests: XCTestCase { // swiftlint:disable:this type_body
2626
masterKey: "masterKey",
2727
serverURL: url,
2828
testing: true)
29-
ParseLiveQuery.setDefault(try ParseLiveQuery(isDefault: true))
29+
ParseLiveQuery.defaultClient = try ParseLiveQuery(isDefault: true)
3030
}
3131

3232
override func tearDownWithError() throws {

Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ParseLiveQueryCombineTests: XCTestCase {
2727
masterKey: "masterKey",
2828
serverURL: url,
2929
testing: true)
30-
ParseLiveQuery.setDefault(try ParseLiveQuery(isDefault: true))
30+
ParseLiveQuery.defaultClient = try ParseLiveQuery(isDefault: true)
3131
}
3232

3333
override func tearDownWithError() throws {

0 commit comments

Comments
 (0)