Files
photochk/Sources/Photochk/Models/PhotoAsset.swift
T
2026-07-27 15:40:30 +00:00

41 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}()
}