45 lines
920 B
Swift
45 lines
920 B
Swift
import Foundation
|
|
|
|
final class FileResource: ObservableObject {
|
|
|
|
let type: FileType
|
|
|
|
/// Globally unique id
|
|
@Published
|
|
var uniqueId: String
|
|
|
|
@Published
|
|
var description: String
|
|
|
|
init(uniqueId: String, description: String) {
|
|
self.type = FileType(fileExtension: uniqueId.fileExtension)
|
|
self.uniqueId = uniqueId
|
|
self.description = description
|
|
}
|
|
|
|
init(type: FileType, uniqueId: String, description: String) {
|
|
self.type = type
|
|
self.uniqueId = uniqueId
|
|
self.description = description
|
|
}
|
|
}
|
|
|
|
extension FileResource: Identifiable {
|
|
|
|
var id: String { uniqueId }
|
|
}
|
|
|
|
extension FileResource: Equatable {
|
|
|
|
static func == (lhs: FileResource, rhs: FileResource) -> Bool {
|
|
lhs.uniqueId == rhs.uniqueId
|
|
}
|
|
}
|
|
|
|
extension FileResource: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(uniqueId)
|
|
}
|
|
}
|