55 lines
1.0 KiB
Swift
55 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
final class FileToAdd: ObservableObject {
|
|
|
|
let id: Int
|
|
|
|
unowned let content: Content
|
|
|
|
// The external path to the file, or nil if the file is just a placeholder
|
|
let url: URL?
|
|
|
|
@Published
|
|
var uniqueId: String
|
|
|
|
@Published
|
|
var isSelected: Bool = true
|
|
|
|
init(content: Content, url: URL) {
|
|
self.id = .random()
|
|
self.content = content
|
|
self.url = url
|
|
self.uniqueId = url.lastPathComponent
|
|
}
|
|
|
|
init(content: Content, externalFile: String) {
|
|
self.id = .random()
|
|
self.content = content
|
|
self.url = nil
|
|
self.uniqueId = externalFile
|
|
}
|
|
|
|
var idAlreadyExists: Bool {
|
|
content.files.contains { $0.id == uniqueId }
|
|
}
|
|
}
|
|
|
|
extension FileToAdd: Identifiable {
|
|
|
|
}
|
|
|
|
extension FileToAdd: Equatable {
|
|
|
|
static func == (lhs: FileToAdd, rhs: FileToAdd) -> Bool {
|
|
lhs.url == rhs.url
|
|
}
|
|
}
|
|
|
|
extension FileToAdd: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(url)
|
|
}
|
|
}
|
|
|