@@ -10,7 +10,7 @@ import Foundation
10
10
11
11
/**
12
12
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
14
14
`ParseObject` protocol, and retains the same functionality of a `ParseObject`, but also extends
15
15
it with installation-specific fields and related immutability and validity
16
16
checks.
@@ -21,16 +21,15 @@ import Foundation
21
21
is automatically updated to match the device's time zone
22
22
when the `ParseInstallation` is saved, thus these fields might not reflect the
23
23
latest device state if the installation has not recently been saved.
24
-
25
24
`ParseInstallation`s which have a valid `deviceToken` and are saved to
26
25
the Parse Server can be used to target push notifications. Use `setDeviceToken` to set the
27
26
`deviceToken` properly.
28
27
29
28
- 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.
34
33
*/
35
34
public protocol ParseInstallation : ParseObject {
36
35
@@ -479,13 +478,12 @@ extension ParseInstallation {
479
478
try Self . updateKeychainIfNeeded ( [ foundResult] )
480
479
completion ( . success( foundResult) )
481
480
} 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 ) )
487
486
}
488
- completion ( . failure( returnError) )
489
487
}
490
488
} else {
491
489
completion ( result)
@@ -533,6 +531,7 @@ extension ParseInstallation {
533
531
- returns: Returns saved `ParseInstallation`.
534
532
- important: If an object saved has the same objectId as current, it will automatically update the current.
535
533
*/
534
+ @discardableResult
536
535
public func save( options: API . Options = [ ] ) throws -> Self {
537
536
try save ( ignoringCustomObjectIdConfig: false ,
538
537
options: options)
@@ -560,6 +559,7 @@ extension ParseInstallation {
560
559
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
561
560
desires a different policy, it should be inserted in `options`.
562
561
*/
562
+ @discardableResult
563
563
public func save( ignoringCustomObjectIdConfig: Bool ,
564
564
options: API . Options = [ ] ) throws -> Self {
565
565
var options = options
@@ -724,12 +724,11 @@ extension ParseInstallation {
724
724
completion ( result)
725
725
}
726
726
} catch {
727
+ let defaultError = ParseError ( code: . unknownError,
728
+ message: error. localizedDescription)
729
+ let parseError = error as? ParseError ?? defaultError
727
730
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) )
733
732
}
734
733
}
735
734
return
@@ -862,13 +861,12 @@ extension ParseInstallation {
862
861
try Self . updateKeychainIfNeeded ( [ self ] , deleting: true )
863
862
completion ( . success( ( ) ) )
864
863
} 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 ) )
870
869
}
871
- completion ( . failure( returnError) )
872
870
}
873
871
case . failure( let error) :
874
872
completion ( . failure( error) )
@@ -937,6 +935,7 @@ public extension Sequence where Element: ParseInstallation {
937
935
- note: The default cache policy for this method is `.reloadIgnoringLocalCacheData`. If a developer
938
936
desires a different policy, it should be inserted in `options`.
939
937
*/
938
+ @discardableResult
940
939
func saveAll( batchLimit limit: Int ? = nil , // swiftlint:disable:this function_body_length
941
940
transaction: Bool = configuration. isUsingTransactions,
942
941
ignoringCustomObjectIdConfig: Bool = false ,
@@ -1232,12 +1231,11 @@ public extension Sequence where Element: ParseInstallation {
1232
1231
commands. append ( try installation. updateCommand ( ) )
1233
1232
}
1234
1233
} catch {
1234
+ let defaultError = ParseError ( code: . unknownError,
1235
+ message: error. localizedDescription)
1236
+ let parseError = error as? ParseError ?? defaultError
1235
1237
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) )
1241
1239
}
1242
1240
return
1243
1241
}
@@ -1275,12 +1273,11 @@ public extension Sequence where Element: ParseInstallation {
1275
1273
}
1276
1274
}
1277
1275
} catch {
1276
+ let defaultError = ParseError ( code: . unknownError,
1277
+ message: error. localizedDescription)
1278
+ let parseError = error as? ParseError ?? defaultError
1278
1279
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) )
1284
1281
}
1285
1282
}
1286
1283
}
@@ -1499,12 +1496,10 @@ public extension Sequence where Element: ParseInstallation {
1499
1496
}
1500
1497
}
1501
1498
} catch {
1499
+ let defaultError = ParseError ( code: . unknownError,
1500
+ message: error. localizedDescription)
1501
+ let parseError = error as? ParseError ?? defaultError
1502
1502
callbackQueue. async {
1503
- guard let parseError = error as? ParseError else {
1504
- completion ( . failure( ParseError ( code: . unknownError,
1505
- message: error. localizedDescription) ) )
1506
- return
1507
- }
1508
1503
completion ( . failure( parseError) )
1509
1504
}
1510
1505
}
0 commit comments