41 lines
1.1 KiB
Swift
41 lines
1.1 KiB
Swift
import Foundation
|
||
|
||
/// スキャン対象の写真1枚。ファイル URL を同一性とする。
|
||
struct PhotoAsset: Identifiable, Hashable, Sendable {
|
||
var id: URL { url }
|
||
|
||
let url: URL
|
||
let fileSize: Int64
|
||
let modificationDate: Date
|
||
|
||
/// EXIF の撮影日時。無ければファイルの作成日。
|
||
var captureDate: Date?
|
||
var pixelWidth: Int
|
||
var pixelHeight: Int
|
||
|
||
var fileName: String { url.lastPathComponent }
|
||
|
||
/// 画素数。代表選出の第一基準。
|
||
var pixelCount: Int { pixelWidth * pixelHeight }
|
||
|
||
var dimensionText: String {
|
||
pixelWidth > 0 && pixelHeight > 0 ? "\(pixelWidth) × \(pixelHeight)" : "—"
|
||
}
|
||
|
||
var fileSizeText: String {
|
||
ByteCountFormatter.string(fromByteCount: fileSize, countStyle: .file)
|
||
}
|
||
|
||
var captureDateText: String {
|
||
guard let captureDate else { return "—" }
|
||
return PhotoAsset.displayDateFormatter.string(from: captureDate)
|
||
}
|
||
|
||
private static let displayDateFormatter: DateFormatter = {
|
||
let f = DateFormatter()
|
||
f.dateStyle = .medium
|
||
f.timeStyle = .short
|
||
return f
|
||
}()
|
||
}
|