Tutorials ⟩ Model
Landmark.swift (8)
ModelData.swift (9)
Hike.swift (10)
Profile.swift (11)
import Foundation
import SwiftUI
import CoreLocation
struct Landmark: Hashable, Codable, Identifiable {
/// property required by `Identifiable` protocol;
var id: Int
var name: String
var park: String
var state: String
var description: String
var isFavorite: Bool
var isFeatured: Bool
var category: Category
/// Landmark.Category
enum Category: String, CaseIterable, Codable {
case lakes = "Lakes"
case rivers = "Rivers"
case mountains = "Mountains"
}
// MARK: - image
private var imageName: String
/// loads an image from the asset catalog.
var image: Image { Image(imageName) }
// MARK: - coordinates
/// for JSON decoding
struct Coordinates: Hashable, Codable {
var latitude: Double
var longitude: Double
}
private var coordinates: Coordinates
var locationCoordinate: CLLocationCoordinate2D {
CLLocationCoordinate2D(
latitude: coordinates.latitude,
longitude: coordinates.longitude
)
}
}
Last updated
Was this helpful?