Files
Gas-Tank-AR-App/GasTankAR/Model/ProjectPhoto.swift
2026-09-02 20:54:36 +02:00

50 lines
1.5 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.

//
// ProjectPhoto.swift
// GasTankAR
//
// Created by Dennis Nemec on 27.08.26.
//
import Foundation
import SwiftData
import CoreLocation
/// Ein im AR-Modus aufgenommenes Foto (Snapshot der Kamera-Sicht), das zu einem Projekt gehört.
/// Die Bilddaten liegen wegen ihrer Größe extern (`.externalStorage`).
@Model
final class ProjectPhoto {
/// Aufnahmezeitpunkt – Grundlage für die Gruppierung in der Galerie.
var creationDate: Date
/// JPEG-kodierte Bilddaten.
@Attribute(.externalStorage) var imageData: Data
/// Geografische Breite des Aufnahmeorts, sofern beim Aufnehmen ein Standort vorlag.
var latitude: Double?
/// Geografische Länge des Aufnahmeorts, sofern beim Aufnehmen ein Standort vorlag.
var longitude: Double?
/// Zugehöriges Projekt (Rückbeziehung zu `Project.photos`).
var project: Project?
init(
creationDate: Date,
imageData: Data,
latitude: Double? = nil,
longitude: Double? = nil,
project: Project? = nil
) {
self.creationDate = creationDate
self.imageData = imageData
self.latitude = latitude
self.longitude = longitude
self.project = project
}
/// Aufnahmeort als Koordinate – `nil`, wenn kein Standort gespeichert wurde.
var coordinate: CLLocationCoordinate2D? {
guard let latitude, let longitude else { return nil }
return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
}