From 39e92a9fbc1d5f7046511778a8d519cb5137e9b9 Mon Sep 17 00:00:00 2001 From: Lukas Smilek Date: Mon, 2 Aug 2021 15:36:55 +0200 Subject: [PATCH] Added warning in playgrounds related to: - mixed environment with both custom and server generated objectId not supported - ParseObject.fetch() returns empty object instead of .objectNotFound ParseError Removing random Int in the reconnection interval of ParseLiveQuery If socket is being open by user, there is no reason for delay -> Added boolean check --- .../Contents.swift | 5 +++++ .../Contents.swift | 10 ++++++++++ Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift | 5 +++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift index e95c47028..af05c2c53 100644 --- a/ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift @@ -239,6 +239,11 @@ let scoreToFetch = GameScore(objectId: savedScore?.objectId) //: Asynchronously (preferred way) fetch this GameScore based on it's objectId alone. scoreToFetch.fetch { result in + /*: Warning: server does return empty object {} instead of a ParseServer error `.objectNotFount` + if the object does not exist yet. This might result in decoding the result into a empty + struct. User `query.first()` of `query.find()` instead if your would like to recieve + and handle an `.objectNotFount` error + */ switch result { case .success(let fetchedScore): print("Successfully fetched: \(fetchedScore)") diff --git a/ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift index 68e2ca5e6..c019724d1 100644 --- a/ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/15 - Custom ObjectId.xcplaygroundpage/Contents.swift @@ -18,6 +18,11 @@ npm start -- --appId applicationId --clientKey clientKey --masterKey masterKey - /*: In Xcode, make sure you are building the "ParseSwift (macOS)" framework. */ +/*: Warning: A mixed environment with both custom and server generated ObjectId + is not supported. SDK throws error if set to use custom objectId + but any object without defined objectId should be saved +*/ + initializeParseCustomObjectId() //: Create your own value typed `ParseObject`. @@ -89,6 +94,11 @@ score.fetch { result in switch result { case .success(let fetchedScore): print("Successfully fetched: \(fetchedScore)") + /*: Warning: server does return empty object {} instead of a ParseServer error `.objectNotFount` + if the object does not exist yet. This might result in decoding the result into a empty + struct. User `query.first()` of `query.find()` instead if your would like to recieve + and handle an `.objectNotFount` error + */ case .failure(let error): assertionFailure("Error fetching: \(error)") } diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index e3130075b..f5a7b32ab 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -223,7 +223,7 @@ extension ParseLiveQuery { var reconnectInterval: Int { let min = NSDecimalNumber(decimal: Swift.min(30, pow(2, attempts) - 1)) - return Int.random(in: 0 ..< Int(truncating: min)) + return Int(truncating: min) } func resumeTask(completion: @escaping (Error?) -> Void) { @@ -577,9 +577,10 @@ extension ParseLiveQuery { completion(error) } } else { + let delay = isUserWantsToConnect ? 0 : reconnectInterval self.synchronizationQueue .asyncAfter(deadline: .now() + DispatchTimeInterval - .seconds(reconnectInterval)) { + .seconds(delay)) { self.attempts += 1 self.resumeTask { _ in } let error = ParseError(code: .unknownError,