Skip to content

Commit cb223d4

Browse files
committed
Expose Subscription properties
1 parent 39f20d2 commit cb223d4

File tree

6 files changed

+111
-86
lines changed

6 files changed

+111
-86
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.0...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.1...main)
55
* _Contributing to this repo? Add info about your change here to be included in next release_
66

7+
### 1.1.1
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.0...1.1.1)
9+
10+
__Fixes__
11+
- Expose `ParseLiveQuery` subscription properties ([#66](https://github.com/parse-community/Parse-Swift/pull/66)), thanks to [Corey Baker](https://github.com/cbaker6).
12+
713
### 1.1.0
814
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.0.2...1.1.0)
915

ParseSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.1.0"
3+
s.version = "1.1.1"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
705A9A3025991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; };
106106
705A9A3125991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; };
107107
705A9A3225991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; };
108+
705D950825BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; };
109+
705D950925BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; };
110+
705D950A25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; };
111+
705D950B25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; };
108112
70647E8E259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; };
109113
70647E8F259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; };
110114
70647E90259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; };
@@ -469,6 +473,7 @@
469473
705727882593FF8000F0ADD5 /* ParseFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseFileTests.swift; sourceTree = "<group>"; };
470474
705A99F8259807F900B3547F /* ParseFileManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseFileManagerTests.swift; sourceTree = "<group>"; };
471475
705A9A2E25991C1400B3547F /* Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fileable.swift; sourceTree = "<group>"; };
476+
705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionCallback.swift; sourceTree = "<group>"; };
472477
70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocallyIdentifiable.swift; sourceTree = "<group>"; };
473478
70647E9B259E3A9A004C1004 /* ParseType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseType.swift; sourceTree = "<group>"; };
474479
707A3BF025B0A4F0000D215C /* ParseAuthentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAuthentication.swift; sourceTree = "<group>"; };
@@ -825,6 +830,7 @@
825830
700395A225A119430052CB31 /* Operations.swift */,
826831
7003960825A184EF0052CB31 /* ParseLiveQuery.swift */,
827832
700395B925A1470F0052CB31 /* Subscription.swift */,
833+
705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */,
828834
700395DE25A147C40052CB31 /* Protocols */,
829835
);
830836
path = LiveQuery;
@@ -1437,6 +1443,7 @@
14371443
707A3C2025B14BD0000D215C /* ParseApple.swift in Sources */,
14381444
F97B462224D9C6F200F4A88B /* ParseKeyValueStore.swift in Sources */,
14391445
F97B45E624D9C6F200F4A88B /* Query.swift in Sources */,
1446+
705D950825BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */,
14401447
70C5509225B4A99100B5DBC2 /* AddRelation.swift in Sources */,
14411448
708D035225215F9B00646C70 /* Deletable.swift in Sources */,
14421449
F97B466424D9C88600F4A88B /* SecureStorage.swift in Sources */,
@@ -1548,6 +1555,7 @@
15481555
707A3C2125B14BD0000D215C /* ParseApple.swift in Sources */,
15491556
F97B462324D9C6F200F4A88B /* ParseKeyValueStore.swift in Sources */,
15501557
F97B45E724D9C6F200F4A88B /* Query.swift in Sources */,
1558+
705D950925BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */,
15511559
70C5509325B4A99100B5DBC2 /* AddRelation.swift in Sources */,
15521560
708D035325215F9B00646C70 /* Deletable.swift in Sources */,
15531561
F97B466524D9C88600F4A88B /* SecureStorage.swift in Sources */,
@@ -1705,6 +1713,7 @@
17051713
707A3C2325B14BD0000D215C /* ParseApple.swift in Sources */,
17061714
F97B462124D9C6F200F4A88B /* ParseStorage.swift in Sources */,
17071715
F97B466724D9C88600F4A88B /* SecureStorage.swift in Sources */,
1716+
705D950B25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */,
17081717
70C5509525B4A99100B5DBC2 /* AddRelation.swift in Sources */,
17091718
708D035525215F9B00646C70 /* Deletable.swift in Sources */,
17101719
70110D55250680140091CC1D /* ParseConstants.swift in Sources */,
@@ -1779,6 +1788,7 @@
17791788
707A3C2225B14BD0000D215C /* ParseApple.swift in Sources */,
17801789
F97B462024D9C6F200F4A88B /* ParseStorage.swift in Sources */,
17811790
F97B466624D9C88600F4A88B /* SecureStorage.swift in Sources */,
1791+
705D950A25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */,
17821792
70C5509425B4A99100B5DBC2 /* AddRelation.swift in Sources */,
17831793
708D035425215F9B00646C70 /* Deletable.swift in Sources */,
17841794
70110D54250680140091CC1D /* ParseConstants.swift in Sources */,
@@ -2045,7 +2055,7 @@
20452055
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
20462056
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
20472057
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2048-
MARKETING_VERSION = 1.1.0;
2058+
MARKETING_VERSION = 1.1.1;
20492059
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
20502060
PRODUCT_NAME = ParseSwift;
20512061
SKIP_INSTALL = YES;
@@ -2067,7 +2077,7 @@
20672077
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
20682078
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
20692079
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2070-
MARKETING_VERSION = 1.1.0;
2080+
MARKETING_VERSION = 1.1.1;
20712081
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
20722082
PRODUCT_NAME = ParseSwift;
20732083
SKIP_INSTALL = YES;
@@ -2131,7 +2141,7 @@
21312141
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
21322142
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
21332143
MACOSX_DEPLOYMENT_TARGET = 10.13;
2134-
MARKETING_VERSION = 1.1.0;
2144+
MARKETING_VERSION = 1.1.1;
21352145
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
21362146
PRODUCT_NAME = ParseSwift;
21372147
SDKROOT = macosx;
@@ -2155,7 +2165,7 @@
21552165
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
21562166
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
21572167
MACOSX_DEPLOYMENT_TARGET = 10.13;
2158-
MARKETING_VERSION = 1.1.0;
2168+
MARKETING_VERSION = 1.1.1;
21592169
PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift;
21602170
PRODUCT_NAME = ParseSwift;
21612171
SDKROOT = macosx;
@@ -2300,7 +2310,7 @@
23002310
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
23012311
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23022312
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2303-
MARKETING_VERSION = 1.1.0;
2313+
MARKETING_VERSION = 1.1.1;
23042314
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
23052315
MTL_FAST_MATH = YES;
23062316
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
@@ -2328,7 +2338,7 @@
23282338
INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist";
23292339
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23302340
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2331-
MARKETING_VERSION = 1.1.0;
2341+
MARKETING_VERSION = 1.1.1;
23322342
MTL_FAST_MATH = YES;
23332343
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS";
23342344
PRODUCT_NAME = ParseSwift;
@@ -2354,7 +2364,7 @@
23542364
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
23552365
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23562366
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2357-
MARKETING_VERSION = 1.1.0;
2367+
MARKETING_VERSION = 1.1.1;
23582368
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
23592369
MTL_FAST_MATH = YES;
23602370
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
@@ -2381,7 +2391,7 @@
23812391
INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist";
23822392
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
23832393
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
2384-
MARKETING_VERSION = 1.1.0;
2394+
MARKETING_VERSION = 1.1.1;
23852395
MTL_FAST_MATH = YES;
23862396
PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS";
23872397
PRODUCT_NAME = ParseSwift;

Scripts/jazzy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bundle exec jazzy \
55
--author_url http://parseplatform.org \
66
--github_url https://github.com/parse-community/Parse-Swift \
77
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.1.0 \
8+
--module-version 1.1.1 \
99
--theme fullwidth \
1010
--skip-undocumented \
1111
--output ./docs/api \

Sources/ParseSwift/LiveQuery/Subscription.swift

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ open class Subscription<T: ParseObject>: ParseSubscription, ObservableObject {
6969
//The ParseObject
7070
public typealias Object = T
7171

72-
/// Notifies there's a new event related to a specific query.
73-
private (set) var event: (query: Query<T>, event: Event<T>)? {
72+
/// Updates and notifies when there's a new event related to a specific query.
73+
public internal(set) var event: (query: Query<T>, event: Event<T>)? {
7474
willSet {
7575
if newValue != nil {
7676
subscribed = nil
@@ -80,8 +80,8 @@ open class Subscription<T: ParseObject>: ParseSubscription, ObservableObject {
8080
}
8181
}
8282

83-
/// Notifies when a subscription request has been fulfilled and if it is new.
84-
private (set) var subscribed: (query: Query<T>, isNew: Bool)? {
83+
/// Updates and notifies when a subscription request has been fulfilled and if it is new.
84+
public internal(set) var subscribed: (query: Query<T>, isNew: Bool)? {
8585
willSet {
8686
if newValue != nil {
8787
unsubscribed = nil
@@ -91,8 +91,8 @@ open class Subscription<T: ParseObject>: ParseSubscription, ObservableObject {
9191
}
9292
}
9393

94-
/// Notifies when an unsubscribe request has been fulfilled.
95-
private (set) var unsubscribed: Query<T>? {
94+
/// Updates and notifies when an unsubscribe request has been fulfilled.
95+
public internal(set) var unsubscribed: Query<T>? {
9696
willSet {
9797
if newValue != nil {
9898
subscribed = nil
@@ -131,75 +131,6 @@ open class Subscription<T: ParseObject>: ParseSubscription, ObservableObject {
131131
}
132132
#endif
133133

134-
/**
135-
A default implementation of the `ParseSubscription` protocol using closures for callbacks.
136-
*/
137-
open class SubscriptionCallback<T: ParseObject>: ParseSubscription {
138-
//The query subscribed to.
139-
public var query: Query<T>
140-
//The ParseObject
141-
public typealias Object = T
142-
fileprivate var eventHandlers: [(Query<T>, Event<T>) -> Void] = []
143-
fileprivate var subscribeHandlers: [(Query<T>, Bool) -> Void] = []
144-
fileprivate var unsubscribeHandlers: [(Query<T>) -> Void] = []
145-
146-
/**
147-
Creates a new subscription that can be used to handle updates.
148-
*/
149-
public init(query: Query<T>) {
150-
self.query = query
151-
}
152-
153-
/**
154-
Register a callback for when an event occurs.
155-
- parameter handler: The callback to register.
156-
- returns: The same subscription, for easy chaining.
157-
*/
158-
@discardableResult open func handleEvent(_ handler: @escaping (Query<T>,
159-
Event<T>) -> Void) -> SubscriptionCallback {
160-
eventHandlers.append(handler)
161-
return self
162-
}
163-
164-
/**
165-
Register a callback for when a client succesfully subscribes to a query.
166-
- parameter handler: The callback to register.
167-
- returns: The same subscription, for easy chaining.
168-
*/
169-
@discardableResult open func handleSubscribe(_ handler: @escaping (Query<T>,
170-
Bool) -> Void) -> SubscriptionCallback {
171-
subscribeHandlers.append(handler)
172-
return self
173-
}
174-
175-
/**
176-
Register a callback for when a query has been unsubscribed.
177-
- parameter handler: The callback to register.
178-
- returns: The same subscription, for easy chaining.
179-
*/
180-
@discardableResult open func handleUnsubscribe(_ handler: @escaping (Query<T>) -> Void) -> SubscriptionCallback {
181-
unsubscribeHandlers.append(handler)
182-
return self
183-
}
184-
185-
open func didReceive(_ eventData: Data) throws {
186-
// Need to decode the event with respect to the `ParseObject`.
187-
let eventMessage = try ParseCoding.jsonDecoder().decode(EventResponse<T>.self, from: eventData)
188-
guard let event = Event(event: eventMessage) else {
189-
throw ParseError(code: .unknownError, message: "ParseLiveQuery Error: couldn't create event.")
190-
}
191-
eventHandlers.forEach { $0(query, event) }
192-
}
193-
194-
open func didSubscribe(_ new: Bool) {
195-
subscribeHandlers.forEach { $0(query, new) }
196-
}
197-
198-
open func didUnsubscribe() {
199-
unsubscribeHandlers.forEach { $0(query) }
200-
}
201-
}
202-
203134
extension SubscriptionCallback {
204135

205136
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// SubscriptionCallback.swift
3+
// ParseSwift
4+
//
5+
// Created by Corey Baker on 1/24/21.
6+
// Copyright © 2021 Parse Community. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
A default implementation of the `ParseSubscription` protocol using closures for callbacks.
13+
*/
14+
open class SubscriptionCallback<T: ParseObject>: ParseSubscription {
15+
//The query subscribed to.
16+
public var query: Query<T>
17+
//The ParseObject
18+
public typealias Object = T
19+
fileprivate var eventHandlers: [(Query<T>, Event<T>) -> Void] = []
20+
fileprivate var subscribeHandlers: [(Query<T>, Bool) -> Void] = []
21+
fileprivate var unsubscribeHandlers: [(Query<T>) -> Void] = []
22+
23+
/**
24+
Creates a new subscription that can be used to handle updates.
25+
*/
26+
public init(query: Query<T>) {
27+
self.query = query
28+
}
29+
30+
/**
31+
Register a callback for when an event occurs.
32+
- parameter handler: The callback to register.
33+
- returns: The same subscription, for easy chaining.
34+
*/
35+
@discardableResult open func handleEvent(_ handler: @escaping (Query<T>,
36+
Event<T>) -> Void) -> SubscriptionCallback {
37+
eventHandlers.append(handler)
38+
return self
39+
}
40+
41+
/**
42+
Register a callback for when a client succesfully subscribes to a query.
43+
- parameter handler: The callback to register.
44+
- returns: The same subscription, for easy chaining.
45+
*/
46+
@discardableResult open func handleSubscribe(_ handler: @escaping (Query<T>,
47+
Bool) -> Void) -> SubscriptionCallback {
48+
subscribeHandlers.append(handler)
49+
return self
50+
}
51+
52+
/**
53+
Register a callback for when a query has been unsubscribed.
54+
- parameter handler: The callback to register.
55+
- returns: The same subscription, for easy chaining.
56+
*/
57+
@discardableResult open func handleUnsubscribe(_ handler: @escaping (Query<T>) -> Void) -> SubscriptionCallback {
58+
unsubscribeHandlers.append(handler)
59+
return self
60+
}
61+
62+
open func didReceive(_ eventData: Data) throws {
63+
// Need to decode the event with respect to the `ParseObject`.
64+
let eventMessage = try ParseCoding.jsonDecoder().decode(EventResponse<T>.self, from: eventData)
65+
guard let event = Event(event: eventMessage) else {
66+
throw ParseError(code: .unknownError, message: "ParseLiveQuery Error: couldn't create event.")
67+
}
68+
eventHandlers.forEach { $0(query, event) }
69+
}
70+
71+
open func didSubscribe(_ new: Bool) {
72+
subscribeHandlers.forEach { $0(query, new) }
73+
}
74+
75+
open func didUnsubscribe() {
76+
unsubscribeHandlers.forEach { $0(query) }
77+
}
78+
}

0 commit comments

Comments
 (0)