LandmarkDetail.swift


  1. import SwiftUI
  2. struct LandmarkDetail: View {
  3. @EnvironmentObject var modelData: ModelData
  4. var landmark: Landmark
  5. var landmarkIndex: Int {
  6. modelData.landmarks.firstIndex(where: { $0.id == landmark.id })!
  7. }
  8. var body: some View {
  9. VStack {
  10. CircleImage(image: landmark.image.resizable())
  11. .scaledToFill()
  12. Text(landmark.name)
  13. .font(.headline)
  14. .lineLimit(0)
  15. Toggle(isOn: $modelData.landmarks[landmarkIndex].isFavorite) {
  16. Text("Favorite")
  17. }
  18. Divider()
  19. Text(landmark.park)
  20. .font(.caption)
  21. .bold()
  22. .lineLimit(0)
  23. Text(landmark.state)
  24. .font(.caption)
  25. }
  26. }
  27. }
  28. struct LandmarkDetail_Previews: PreviewProvider {
  29. static var previews: some View {
  30. let modelData = ModelData()
  31. return Group {
  32. LandmarkDetail(landmark: modelData.landmarks[0])
  33. .environmentObject(modelData)
  34. .previewDevice("Apple Watch Series 5 - 44mm")
  35. LandmarkDetail(landmark: modelData.landmarks[1])
  36. .environmentObject(modelData)
  37. .previewDevice("Apple Watch Series 5 - 40mm")
  38. }
  39. }
  40. }