@@ -10,7 +10,7 @@ import Foundation
1010
1111/**
1212 Objects that conform to the `ParseInstallation` protocol have a local representation of an
13- installation persisted to the Parse cloud . This protocol inherits from the
13+ installation persisted to the Keychain and Parse Server . This protocol inherits from the
1414 `ParseObject` protocol, and retains the same functionality of a `ParseObject`, but also extends
1515 it with installation-specific fields and related immutability and validity
1616 checks.
@@ -21,16 +21,15 @@ import Foundation
2121 is automatically updated to match the device's time zone
2222 when the `ParseInstallation` is saved, thus these fields might not reflect the
2323 latest device state if the installation has not recently been saved.
24-
2524 `ParseInstallation`s which have a valid `deviceToken` and are saved to
2625 the Parse Server can be used to target push notifications. Use `setDeviceToken` to set the
2726 `deviceToken` properly.
2827
2928 - warning: If the use of badge is desired, it should be retrieved by using UIKit, AppKit, etc. and
30- stored in `ParseInstallation.badge` before saving/updating the installation.
31-
32- - warning: Linux developers should set `appName`, ` appIdentifier`, and `appVersion`
33- manually as `ParseSwift` does not have access to Bundle.main.
29+ stored in `ParseInstallation.badge` when saving/updating the installation.
30+ - warning: Linux, Android, and Windows developers should set `appName`,
31+ ` appIdentifier`, and `appVersion` manually as `ParseSwift` does not have access
32+ to Bundle.main.
3433*/
3534public protocol ParseInstallation : ParseObject {
3635
@@ -479,13 +478,12 @@ extension ParseInstallation {
479478 try Self . updateKeychainIfNeeded ( [ foundResult] )
480479 completion ( . success( foundResult) )
481480 } catch {
482- let returnError : ParseError !
483- if let parseError = error as? ParseError {
484- returnError = parseError
485- } else {
486- returnError = ParseError ( code : . unknownError , message : error . localizedDescription )
481+ let defaultError = ParseError ( code : . unknownError ,
482+ message : error . localizedDescription )
483+ let parseError = error as? ParseError ?? defaultError
484+ callbackQueue . async {
485+ completion ( . failure ( parseError ) )
487486 }
488- completion ( . failure( returnError) )
489487 }
490488 } else {
491489 completion ( result)
@@ -533,6 +531,7 @@ extension ParseInstallation {
533531 - returns: Returns saved `ParseInstallation`.
534532 - important: If an object saved has the same objectId as current, it will automatically update the current.
535533 */
534+ @discardableResult
536535 public func save( options: API . Options = [ ] ) throws -> Self {
537536 try save ( ignoringCustomObjectIdConfig: false ,
538537 options: options)
@@ -560,6 +559,7 @@ extension ParseInstallation {
560559 - note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
561560 desires a different policy, it should be inserted in `options`.
562561 */
562+ @discardableResult
563563 public func save( ignoringCustomObjectIdConfig: Bool ,
564564 options: API . Options = [ ] ) throws -> Self {
565565 var options = options
@@ -724,12 +724,11 @@ extension ParseInstallation {
724724 completion ( result)
725725 }
726726 } catch {
727+ let defaultError = ParseError ( code: . unknownError,
728+ message: error. localizedDescription)
729+ let parseError = error as? ParseError ?? defaultError
727730 callbackQueue. async {
728- if let parseError = error as? ParseError {
729- completion ( . failure( parseError) )
730- } else {
731- completion ( . failure( . init( code: . unknownError, message: error. localizedDescription) ) )
732- }
731+ completion ( . failure( parseError) )
733732 }
734733 }
735734 return
@@ -862,13 +861,12 @@ extension ParseInstallation {
862861 try Self . updateKeychainIfNeeded ( [ self ] , deleting: true )
863862 completion ( . success( ( ) ) )
864863 } catch {
865- let returnError : ParseError !
866- if let parseError = error as? ParseError {
867- returnError = parseError
868- } else {
869- returnError = ParseError ( code : . unknownError , message : error . localizedDescription )
864+ let defaultError = ParseError ( code : . unknownError ,
865+ message : error . localizedDescription )
866+ let parseError = error as? ParseError ?? defaultError
867+ callbackQueue . async {
868+ completion ( . failure ( parseError ) )
870869 }
871- completion ( . failure( returnError) )
872870 }
873871 case . failure( let error) :
874872 completion ( . failure( error) )
@@ -937,6 +935,7 @@ public extension Sequence where Element: ParseInstallation {
937935 - note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
938936 desires a different policy, it should be inserted in `options`.
939937 */
938+ @discardableResult
940939 func saveAll( batchLimit limit: Int ? = nil , // swiftlint:disable:this function_body_length
941940 transaction: Bool = configuration. isUsingTransactions,
942941 ignoringCustomObjectIdConfig: Bool = false ,
@@ -1232,12 +1231,11 @@ public extension Sequence where Element: ParseInstallation {
12321231 commands. append ( try installation. updateCommand ( ) )
12331232 }
12341233 } catch {
1234+ let defaultError = ParseError ( code: . unknownError,
1235+ message: error. localizedDescription)
1236+ let parseError = error as? ParseError ?? defaultError
12351237 callbackQueue. async {
1236- if let parseError = error as? ParseError {
1237- completion ( . failure( parseError) )
1238- } else {
1239- completion ( . failure( . init( code: . unknownError, message: error. localizedDescription) ) )
1240- }
1238+ completion ( . failure( parseError) )
12411239 }
12421240 return
12431241 }
@@ -1275,12 +1273,11 @@ public extension Sequence where Element: ParseInstallation {
12751273 }
12761274 }
12771275 } catch {
1276+ let defaultError = ParseError ( code: . unknownError,
1277+ message: error. localizedDescription)
1278+ let parseError = error as? ParseError ?? defaultError
12781279 callbackQueue. async {
1279- if let parseError = error as? ParseError {
1280- completion ( . failure( parseError) )
1281- } else {
1282- completion ( . failure( . init( code: . unknownError, message: error. localizedDescription) ) )
1283- }
1280+ completion ( . failure( parseError) )
12841281 }
12851282 }
12861283 }
@@ -1499,12 +1496,10 @@ public extension Sequence where Element: ParseInstallation {
14991496 }
15001497 }
15011498 } catch {
1499+ let defaultError = ParseError ( code: . unknownError,
1500+ message: error. localizedDescription)
1501+ let parseError = error as? ParseError ?? defaultError
15021502 callbackQueue. async {
1503- guard let parseError = error as? ParseError else {
1504- completion ( . failure( ParseError ( code: . unknownError,
1505- message: error. localizedDescription) ) )
1506- return
1507- }
15081503 completion ( . failure( parseError) )
15091504 }
15101505 }
0 commit comments