From 0f2007ee4b0ec08d9b939e579d97d46b226d3ec4 Mon Sep 17 00:00:00 2001 From: taek0622 Date: Tue, 13 Jun 2023 22:25:55 +0900 Subject: [PATCH] Chore:wrench:: #32 Modify ObservedObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - locationManager를 StateObject와 EnvrionmentObject를 사용하는 방식으로 변경 --- Nav/View/MapView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Nav/View/MapView.swift b/Nav/View/MapView.swift index bdfccb7..dfb644b 100644 --- a/Nav/View/MapView.swift +++ b/Nav/View/MapView.swift @@ -7,7 +7,7 @@ import MapKit import SwiftUI struct MapView: View { - @ObservedObject var locationManager = LocationManager() + @StateObject var locationManager = LocationManager() // 서울 좌표 @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.5666791, longitude: 126.9782914), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)) @@ -22,7 +22,8 @@ struct MapView: View { annotationItems: mockDatas) { data in MapMarker(coordinate: data.coordinate) } - SearchedView(locationManager: locationManager, region: $region) + SearchedView(region: $region) + .environmentObject(locationManager) } .navigationTitle("NAV") .searchable( @@ -35,7 +36,7 @@ struct MapView: View { } private struct SearchedView: View { - let locationManager: LocationManager + @EnvironmentObject var locationManager: LocationManager @Binding var region: MKCoordinateRegion @Environment(\.isSearching) private var isSearching @Environment(\.dismissSearch) private var dismissSearch