Skip to content

Commit 5c3118c

Browse files
authored
fix: Expose isSaved method on ParseFile and ParseOperation (#135)
* fix: Expose isSaved method on ParseFile and ParseOperation * nit changelog * nit
1 parent 5817123 commit 5c3118c

File tree

7 files changed

+29
-3
lines changed

7 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.1...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 5.8.2
9+
[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)
10+
11+
__Fixes__
12+
* Expose isSaved method on ParseFile and ParseOperation ([#135](https://github.com/netreconlab/Parse-Swift/pull/135)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.8.1
915
[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)
1016

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.8.1"
13+
static let version = "5.8.2"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Sources/ParseSwift/Protocols/Savable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public protocol Savable: Encodable {
1111

1212
func save(options: API.Options) async throws -> SavingType
1313
func save() async throws -> SavingType
14+
func isSaved() async throws -> Bool
1415
}
1516

1617
extension Savable {

Sources/ParseSwift/Types/ParseFile.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {
1717

1818
internal var isDownloadNeeded: Bool {
1919
return cloudURL != nil
20-
&& url == nil
20+
&& !isSaved
2121
&& localURL == nil
2222
&& data == nil
2323
}
@@ -163,6 +163,10 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {
163163
hasher.combine(self.id)
164164
}
165165

166+
public func isSaved() async throws -> Bool {
167+
isSaved
168+
}
169+
166170
enum CodingKeys: String, CodingKey {
167171
case url
168172
case name

Sources/ParseSwift/Types/ParseOperation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public struct ParseOperation<T>: Savable,
2828
self.target = target
2929
}
3030

31+
/**
32+
Specifies if this object related to the operation has been saved.
33+
- returns: Returns **true** if this object is saved, **false** otherwise.
34+
- throws: An error of `ParseError` type.
35+
*/
36+
public func isSaved() async throws -> Bool {
37+
try await target.isSaved()
38+
}
39+
3140
/**
3241
An operation that sets a field's value.
3342
- Parameters:

Tests/ParseSwiftTests/ParseFileTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ class ParseFileTests: XCTestCase { // swiftlint:disable:this type_body_length
258258
let savedFile = try await parseFile.save()
259259
XCTAssertEqual(savedFile.name, response.name)
260260
XCTAssertEqual(savedFile.url, response.url)
261+
let isSavedBefore = try await parseFile.isSaved()
262+
XCTAssertFalse(isSavedBefore)
263+
let isSavedAfter = try await savedFile.isSaved()
264+
XCTAssertTrue(isSavedAfter)
261265
}
262266

263267
@MainActor

Tests/ParseSwiftTests/ParseOperationTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class ParseOperationTests: XCTestCase {
155155
XCTAssertEqual(savedUpdatedAt, originalUpdatedAt)
156156
XCTAssertEqual(saved.ACL, scoreOnServer.ACL)
157157
XCTAssertEqual(saved.points, originalPoints-1)
158+
let isSavedAfter = try await operations.isSaved()
159+
XCTAssertTrue(isSavedAfter)
158160
} catch {
159161
XCTFail(error.localizedDescription)
160162
}

0 commit comments

Comments
 (0)