Skip to content

Commit

Permalink
improve identifiable documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Jul 13, 2024
1 parent 71ff26d commit 3ac52ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
24 changes: 14 additions & 10 deletions Sources/ParseSwift/Objects/ParseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ public protocol ParseObject: ParseTypeable,
// MARK: Default Implementations
public extension ParseObject {

/**
A computed property that is a unique identifier and makes it easy to use `ParseObject`'s
as models in MVVM and SwiftUI.
- note: `id` allows `ParseObject`'s to be used even if they have not been saved and/or missing an `objectId`.
- important: `id` will have the same value as `objectId` when a `ParseObject` contains an `objectId`.
*/
var id: String {
objectId ?? UUID().uuidString
}

var mergeable: Self {
guard isSaved,
originalData == nil else {
Expand Down Expand Up @@ -245,6 +235,20 @@ extension ParseObject {
}
}

// MARK: Identifiable
public extension ParseObject {

/**
A computed property that ensures `ParseObject`'s can be uniquely identified across instances.
- note: `id` allows `ParseObject`'s to be uniquely identified even if they have not been saved and/or missing an `objectId`.
- important: `id` will have the same value as `objectId` when a `ParseObject` contains an `objectId`.
*/
var id: String {
objectId ?? UUID().uuidString
}

}

// MARK: Helper Methods
public extension ParseObject {
/**
Expand Down
46 changes: 24 additions & 22 deletions Sources/ParseSwift/Types/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {
&& data == nil
}

/**
A computed property that is a unique identifier and makes it easy to use `ParseFile`'s
as models in MVVM and SwiftUI.
- note: `id` allows `ParseFile`'s to be used even when they are not saved.
- important: `id` will have the same value as `name` when a `ParseFile` is saved.
*/
public var id: String {
guard isSaved else {
guard let cloudURL = cloudURL else {
guard let localURL = localURL else {
guard let data = data else {
return name
}
return "\(name)_\(data)"
}
return combineName(with: localURL)
}
return combineName(with: cloudURL)
}
return name
}

/**
The name of the file.
Before the file is saved, this is the filename given by the user.
Expand Down Expand Up @@ -170,6 +148,30 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {
}
}

// MARK: Identifiable
extension ParseFile {
/**
A computed property that ensures `ParseFile`'s can be uniquely identified across instances.
- note: `id` allows `ParseFile`'s to be uniquely identified even if they have not been saved.
- important: `id` will have the same value as `objectId` when a `ParseObject` contains an `objectId`.
*/
public var id: String {
guard isSaved else {
guard let cloudURL = cloudURL else {
guard let localURL = localURL else {
guard let data = data else {
return name
}
return "\(name)_\(data)"
}
return combineName(with: localURL)

Check warning on line 167 in Sources/ParseSwift/Types/ParseFile.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ParseSwift/Types/ParseFile.swift#L167

Added line #L167 was not covered by tests
}
return combineName(with: cloudURL)
}
return name
}
}

// MARK: Helper Methods (internal)
extension ParseFile {
func combineName(with url: URL) -> String {
Expand Down

0 comments on commit 3ac52ed

Please sign in to comment.