diff --git a/CHANGELOG.md b/CHANGELOG.md index 46072ae92..0a7690d03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ [Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.1...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 5.8.2 +[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.1...5.8.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.8.2/documentation/parseswift) + +__Fixes__ +* Expose isSaved method on ParseFile and ParseOperation ([#135](https://github.com/netreconlab/Parse-Swift/pull/135)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 5.8.1 [Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.0...5.8.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.8.1/documentation/parseswift) diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 445a67e86..7ea1a7470 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "5.8.1" + static let version = "5.8.2" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" static let fileManagementLibraryDirectory = "Library/" diff --git a/Sources/ParseSwift/Protocols/Savable.swift b/Sources/ParseSwift/Protocols/Savable.swift index 7bb9bad4f..10c5a9f3b 100644 --- a/Sources/ParseSwift/Protocols/Savable.swift +++ b/Sources/ParseSwift/Protocols/Savable.swift @@ -11,6 +11,7 @@ public protocol Savable: Encodable { func save(options: API.Options) async throws -> SavingType func save() async throws -> SavingType + func isSaved() async throws -> Bool } extension Savable { diff --git a/Sources/ParseSwift/Types/ParseFile.swift b/Sources/ParseSwift/Types/ParseFile.swift index f8eda9678..0e7cb1ca5 100644 --- a/Sources/ParseSwift/Types/ParseFile.swift +++ b/Sources/ParseSwift/Types/ParseFile.swift @@ -17,7 +17,7 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable { internal var isDownloadNeeded: Bool { return cloudURL != nil - && url == nil + && !isSaved && localURL == nil && data == nil } @@ -163,6 +163,10 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable { hasher.combine(self.id) } + public func isSaved() async throws -> Bool { + isSaved + } + enum CodingKeys: String, CodingKey { case url case name diff --git a/Sources/ParseSwift/Types/ParseOperation.swift b/Sources/ParseSwift/Types/ParseOperation.swift index 77c45762a..b164a5f9d 100644 --- a/Sources/ParseSwift/Types/ParseOperation.swift +++ b/Sources/ParseSwift/Types/ParseOperation.swift @@ -28,6 +28,15 @@ public struct ParseOperation: Savable, self.target = target } + /** + Specifies if this object related to the operation has been saved. + - returns: Returns **true** if this object is saved, **false** otherwise. + - throws: An error of `ParseError` type. + */ + public func isSaved() async throws -> Bool { + try await target.isSaved() + } + /** An operation that sets a field's value. - Parameters: diff --git a/Tests/ParseSwiftTests/ParseFileTests.swift b/Tests/ParseSwiftTests/ParseFileTests.swift index 6ee5dc4ce..9e6a88d10 100644 --- a/Tests/ParseSwiftTests/ParseFileTests.swift +++ b/Tests/ParseSwiftTests/ParseFileTests.swift @@ -258,6 +258,10 @@ class ParseFileTests: XCTestCase { // swiftlint:disable:this type_body_length let savedFile = try await parseFile.save() XCTAssertEqual(savedFile.name, response.name) XCTAssertEqual(savedFile.url, response.url) + let isSavedBefore = try await parseFile.isSaved() + XCTAssertFalse(isSavedBefore) + let isSavedAfter = try await savedFile.isSaved() + XCTAssertTrue(isSavedAfter) } @MainActor diff --git a/Tests/ParseSwiftTests/ParseOperationTests.swift b/Tests/ParseSwiftTests/ParseOperationTests.swift index 2a3cd807b..21fab8b8a 100644 --- a/Tests/ParseSwiftTests/ParseOperationTests.swift +++ b/Tests/ParseSwiftTests/ParseOperationTests.swift @@ -155,6 +155,8 @@ class ParseOperationTests: XCTestCase { XCTAssertEqual(savedUpdatedAt, originalUpdatedAt) XCTAssertEqual(saved.ACL, scoreOnServer.ACL) XCTAssertEqual(saved.points, originalPoints-1) + let isSavedAfter = try await saved.isSaved() + XCTAssertTrue(isSavedAfter) } catch { XCTFail(error.localizedDescription) }