@@ -477,11 +477,12 @@ public extension Sequence where Element: ParseObject {
477
477
- returns: Returns a Result enum with the object if a save was successful or a `ParseError` if it failed.
478
478
- throws: `ParseError`
479
479
*/
480
- func saveAll(options: API.Options = []) throws -> [(Result<PointerType, ParseError>)] {
480
+ func saveAll(transaction: Bool = true,
481
+ options: API.Options = []) throws -> [(Result<PointerType, ParseError>)] {
481
482
let commands = try map { try $0.saveCommand() }
482
483
return try API.Command<Self.Element, PointerType>
483
- .batch(commands: commands)
484
- .execute(options: options)
484
+ .batch(commands: commands, transaction: transaction )
485
+ .execute(options: options, callbackQueue: .main )
485
486
}
486
487
}*/
487
488
@@ -669,7 +670,7 @@ extension ParseObject {
669
670
var waitingToBeSaved = object. unsavedChildren
670
671
671
672
while waitingToBeSaved. count > 0 {
672
- var savableObjects = [ Encodable ] ( )
673
+ var savableObjects = [ ParseType ] ( )
673
674
var savableFiles = [ ParseFile] ( )
674
675
var nextBatch = [ ParseType] ( )
675
676
try waitingToBeSaved. forEach { parseType in
@@ -706,14 +707,21 @@ extension ParseObject {
706
707
}
707
708
708
709
//Currently, batch isn't working for Encodable
709
- /*if let parseTypes = savableObjects as? [ParseType] {
710
- let savedChildObjects = try self.saveAll(options: options, objects: parseTypes)
710
+ /*let savedChildObjects = try Self.saveAll(objects: savableObjects,
711
+ options: options)
712
+ let savedChildPointers = try savedChildObjects.compactMap { try $0.get() }
713
+ if savedChildPointers.count != savableObjects.count {
714
+ throw ParseError(code: .unknownError, message: "Couldn't save all child objects")
715
+ }
716
+ for (index, object) in savableObjects.enumerated() {
717
+ let hash = try BaseObjectable.createHash(object)
718
+ objectsFinishedSaving[hash] = savedChildPointers[index]
711
719
}*/
720
+
721
+ //Saving children individually
712
722
try savableObjects. forEach {
713
723
let hash = try BaseObjectable . createHash ( $0)
714
- if let parseType = $0 as? ParseType {
715
- objectsFinishedSaving [ hash] = try parseType. save ( options: options)
716
- }
724
+ objectsFinishedSaving [ hash] = try $0. save ( options: options)
717
725
}
718
726
719
727
try savableFiles. forEach {
@@ -747,11 +755,17 @@ internal extension ParseType {
747
755
try API . Command < Self , PointerType > . saveCommand ( self )
748
756
}
749
757
/*
750
- func saveAll<T: ParseType>(options: API.Options = [], objects: [T]) throws -> [(Result<PointerType, ParseError>)] {
751
- let commands = try objects.map { try API.Command<T, PointerType>.saveCommand($0) }
752
- return try API.Command<T, PointerType>
753
- .batch(commands: commands)
754
- .execute(options: options)
758
+ static func saveAll(objects: [ParseType],
759
+ transaction: Bool = true,
760
+ options: API.Options = []) throws -> [(Result<PointerType, ParseError>)] {
761
+ let commands = try objects.map {
762
+ try API.Command<Self, PointerType>.saveCommand(object: $0)
763
+ }
764
+ return try API.Command<Self, PointerType>
765
+ .batch(commands: commands,
766
+ transaction: transaction)
767
+ .execute(options: options,
768
+ callbackQueue: .main)
755
769
}*/
756
770
}
757
771
0 commit comments