diff --git a/CHANGELOG.md b/CHANGELOG.md index 53015e154..21983801b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.0...main) +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.1...main) * _Contributing to this repo? Add info about your change here to be included in next release_ +### 1.1.1 +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.0...1.1.1) + +__Fixes__ +- Expose `ParseLiveQuery` subscription properties ([#66](https://github.com/parse-community/Parse-Swift/pull/66)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 1.1.0 [Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.0.2...1.1.0) diff --git a/ParseSwift.podspec b/ParseSwift.podspec index dde2f8f64..53d7d861c 100644 --- a/ParseSwift.podspec +++ b/ParseSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ParseSwift" - s.version = "1.1.0" + s.version = "1.1.1" s.summary = "Parse Pure Swift SDK" s.homepage = "https://github.com/parse-community/Parse-Swift" s.authors = { diff --git a/ParseSwift.xcodeproj/project.pbxproj b/ParseSwift.xcodeproj/project.pbxproj index 8cd11d904..5e801fa2a 100644 --- a/ParseSwift.xcodeproj/project.pbxproj +++ b/ParseSwift.xcodeproj/project.pbxproj @@ -105,6 +105,10 @@ 705A9A3025991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; }; 705A9A3125991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; }; 705A9A3225991C1400B3547F /* Fileable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705A9A2E25991C1400B3547F /* Fileable.swift */; }; + 705D950825BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; }; + 705D950925BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; }; + 705D950A25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; }; + 705D950B25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */; }; 70647E8E259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; }; 70647E8F259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; }; 70647E90259E3375004C1004 /* LocallyIdentifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */; }; @@ -469,6 +473,7 @@ 705727882593FF8000F0ADD5 /* ParseFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseFileTests.swift; sourceTree = ""; }; 705A99F8259807F900B3547F /* ParseFileManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseFileManagerTests.swift; sourceTree = ""; }; 705A9A2E25991C1400B3547F /* Fileable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fileable.swift; sourceTree = ""; }; + 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionCallback.swift; sourceTree = ""; }; 70647E8D259E3375004C1004 /* LocallyIdentifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocallyIdentifiable.swift; sourceTree = ""; }; 70647E9B259E3A9A004C1004 /* ParseType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseType.swift; sourceTree = ""; }; 707A3BF025B0A4F0000D215C /* ParseAuthentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAuthentication.swift; sourceTree = ""; }; @@ -825,6 +830,7 @@ 700395A225A119430052CB31 /* Operations.swift */, 7003960825A184EF0052CB31 /* ParseLiveQuery.swift */, 700395B925A1470F0052CB31 /* Subscription.swift */, + 705D950725BE4C08003EF6F8 /* SubscriptionCallback.swift */, 700395DE25A147C40052CB31 /* Protocols */, ); path = LiveQuery; @@ -1437,6 +1443,7 @@ 707A3C2025B14BD0000D215C /* ParseApple.swift in Sources */, F97B462224D9C6F200F4A88B /* ParseKeyValueStore.swift in Sources */, F97B45E624D9C6F200F4A88B /* Query.swift in Sources */, + 705D950825BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */, 70C5509225B4A99100B5DBC2 /* AddRelation.swift in Sources */, 708D035225215F9B00646C70 /* Deletable.swift in Sources */, F97B466424D9C88600F4A88B /* SecureStorage.swift in Sources */, @@ -1548,6 +1555,7 @@ 707A3C2125B14BD0000D215C /* ParseApple.swift in Sources */, F97B462324D9C6F200F4A88B /* ParseKeyValueStore.swift in Sources */, F97B45E724D9C6F200F4A88B /* Query.swift in Sources */, + 705D950925BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */, 70C5509325B4A99100B5DBC2 /* AddRelation.swift in Sources */, 708D035325215F9B00646C70 /* Deletable.swift in Sources */, F97B466524D9C88600F4A88B /* SecureStorage.swift in Sources */, @@ -1705,6 +1713,7 @@ 707A3C2325B14BD0000D215C /* ParseApple.swift in Sources */, F97B462124D9C6F200F4A88B /* ParseStorage.swift in Sources */, F97B466724D9C88600F4A88B /* SecureStorage.swift in Sources */, + 705D950B25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */, 70C5509525B4A99100B5DBC2 /* AddRelation.swift in Sources */, 708D035525215F9B00646C70 /* Deletable.swift in Sources */, 70110D55250680140091CC1D /* ParseConstants.swift in Sources */, @@ -1779,6 +1788,7 @@ 707A3C2225B14BD0000D215C /* ParseApple.swift in Sources */, F97B462024D9C6F200F4A88B /* ParseStorage.swift in Sources */, F97B466624D9C88600F4A88B /* SecureStorage.swift in Sources */, + 705D950A25BE4C08003EF6F8 /* SubscriptionCallback.swift in Sources */, 70C5509425B4A99100B5DBC2 /* AddRelation.swift in Sources */, 708D035425215F9B00646C70 /* Deletable.swift in Sources */, 70110D54250680140091CC1D /* ParseConstants.swift in Sources */, @@ -2045,7 +2055,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2067,7 +2077,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2131,7 +2141,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2155,7 +2165,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2300,7 +2310,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; @@ -2328,7 +2338,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; PRODUCT_NAME = ParseSwift; @@ -2354,7 +2364,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; @@ -2381,7 +2391,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; PRODUCT_NAME = ParseSwift; diff --git a/Scripts/jazzy.sh b/Scripts/jazzy.sh index 9105572b9..50daa5842 100755 --- a/Scripts/jazzy.sh +++ b/Scripts/jazzy.sh @@ -5,7 +5,7 @@ bundle exec jazzy \ --author_url http://parseplatform.org \ --github_url https://github.com/parse-community/Parse-Swift \ --root-url http://parseplatform.org/Parse-Swift/api/ \ - --module-version 1.1.0 \ + --module-version 1.1.1 \ --theme fullwidth \ --skip-undocumented \ --output ./docs/api \ diff --git a/Sources/ParseSwift/LiveQuery/Subscription.swift b/Sources/ParseSwift/LiveQuery/Subscription.swift index 12b5aef05..f97589586 100644 --- a/Sources/ParseSwift/LiveQuery/Subscription.swift +++ b/Sources/ParseSwift/LiveQuery/Subscription.swift @@ -69,8 +69,8 @@ open class Subscription: ParseSubscription, ObservableObject { //The ParseObject public typealias Object = T - /// Notifies there's a new event related to a specific query. - private (set) var event: (query: Query, event: Event)? { + /// Updates and notifies when there's a new event related to a specific query. + public internal(set) var event: (query: Query, event: Event)? { willSet { if newValue != nil { subscribed = nil @@ -80,8 +80,8 @@ open class Subscription: ParseSubscription, ObservableObject { } } - /// Notifies when a subscription request has been fulfilled and if it is new. - private (set) var subscribed: (query: Query, isNew: Bool)? { + /// Updates and notifies when a subscription request has been fulfilled and if it is new. + public internal(set) var subscribed: (query: Query, isNew: Bool)? { willSet { if newValue != nil { unsubscribed = nil @@ -91,8 +91,8 @@ open class Subscription: ParseSubscription, ObservableObject { } } - /// Notifies when an unsubscribe request has been fulfilled. - private (set) var unsubscribed: Query? { + /// Updates and notifies when an unsubscribe request has been fulfilled. + public internal(set) var unsubscribed: Query? { willSet { if newValue != nil { subscribed = nil @@ -131,75 +131,6 @@ open class Subscription: ParseSubscription, ObservableObject { } #endif -/** - A default implementation of the `ParseSubscription` protocol using closures for callbacks. - */ -open class SubscriptionCallback: ParseSubscription { - //The query subscribed to. - public var query: Query - //The ParseObject - public typealias Object = T - fileprivate var eventHandlers: [(Query, Event) -> Void] = [] - fileprivate var subscribeHandlers: [(Query, Bool) -> Void] = [] - fileprivate var unsubscribeHandlers: [(Query) -> Void] = [] - - /** - Creates a new subscription that can be used to handle updates. - */ - public init(query: Query) { - self.query = query - } - - /** - Register a callback for when an event occurs. - - parameter handler: The callback to register. - - returns: The same subscription, for easy chaining. - */ - @discardableResult open func handleEvent(_ handler: @escaping (Query, - Event) -> Void) -> SubscriptionCallback { - eventHandlers.append(handler) - return self - } - - /** - Register a callback for when a client succesfully subscribes to a query. - - parameter handler: The callback to register. - - returns: The same subscription, for easy chaining. - */ - @discardableResult open func handleSubscribe(_ handler: @escaping (Query, - Bool) -> Void) -> SubscriptionCallback { - subscribeHandlers.append(handler) - return self - } - - /** - Register a callback for when a query has been unsubscribed. - - parameter handler: The callback to register. - - returns: The same subscription, for easy chaining. - */ - @discardableResult open func handleUnsubscribe(_ handler: @escaping (Query) -> Void) -> SubscriptionCallback { - unsubscribeHandlers.append(handler) - return self - } - - open func didReceive(_ eventData: Data) throws { - // Need to decode the event with respect to the `ParseObject`. - let eventMessage = try ParseCoding.jsonDecoder().decode(EventResponse.self, from: eventData) - guard let event = Event(event: eventMessage) else { - throw ParseError(code: .unknownError, message: "ParseLiveQuery Error: couldn't create event.") - } - eventHandlers.forEach { $0(query, event) } - } - - open func didSubscribe(_ new: Bool) { - subscribeHandlers.forEach { $0(query, new) } - } - - open func didUnsubscribe() { - unsubscribeHandlers.forEach { $0(query) } - } -} - extension SubscriptionCallback { /** diff --git a/Sources/ParseSwift/LiveQuery/SubscriptionCallback.swift b/Sources/ParseSwift/LiveQuery/SubscriptionCallback.swift new file mode 100644 index 000000000..01165d956 --- /dev/null +++ b/Sources/ParseSwift/LiveQuery/SubscriptionCallback.swift @@ -0,0 +1,78 @@ +// +// SubscriptionCallback.swift +// ParseSwift +// +// Created by Corey Baker on 1/24/21. +// Copyright © 2021 Parse Community. All rights reserved. +// + +import Foundation + +/** + A default implementation of the `ParseSubscription` protocol using closures for callbacks. + */ +open class SubscriptionCallback: ParseSubscription { + //The query subscribed to. + public var query: Query + //The ParseObject + public typealias Object = T + fileprivate var eventHandlers: [(Query, Event) -> Void] = [] + fileprivate var subscribeHandlers: [(Query, Bool) -> Void] = [] + fileprivate var unsubscribeHandlers: [(Query) -> Void] = [] + + /** + Creates a new subscription that can be used to handle updates. + */ + public init(query: Query) { + self.query = query + } + + /** + Register a callback for when an event occurs. + - parameter handler: The callback to register. + - returns: The same subscription, for easy chaining. + */ + @discardableResult open func handleEvent(_ handler: @escaping (Query, + Event) -> Void) -> SubscriptionCallback { + eventHandlers.append(handler) + return self + } + + /** + Register a callback for when a client succesfully subscribes to a query. + - parameter handler: The callback to register. + - returns: The same subscription, for easy chaining. + */ + @discardableResult open func handleSubscribe(_ handler: @escaping (Query, + Bool) -> Void) -> SubscriptionCallback { + subscribeHandlers.append(handler) + return self + } + + /** + Register a callback for when a query has been unsubscribed. + - parameter handler: The callback to register. + - returns: The same subscription, for easy chaining. + */ + @discardableResult open func handleUnsubscribe(_ handler: @escaping (Query) -> Void) -> SubscriptionCallback { + unsubscribeHandlers.append(handler) + return self + } + + open func didReceive(_ eventData: Data) throws { + // Need to decode the event with respect to the `ParseObject`. + let eventMessage = try ParseCoding.jsonDecoder().decode(EventResponse.self, from: eventData) + guard let event = Event(event: eventMessage) else { + throw ParseError(code: .unknownError, message: "ParseLiveQuery Error: couldn't create event.") + } + eventHandlers.forEach { $0(query, event) } + } + + open func didSubscribe(_ new: Bool) { + subscribeHandlers.forEach { $0(query, new) } + } + + open func didUnsubscribe() { + unsubscribeHandlers.forEach { $0(query) } + } +}