Team-WeHere / WeHere

MIT License
0 stars 0 forks source link

[XCode버그] Xcode 14 “Publishing changes from within view updates is not allowed, this will cause undefined behavior” #20

Open chaneeii opened 1 year ago

chaneeii commented 1 year ago

버그 설명

이쪽코드에서 viewModel 에 바인딩된 내용을 다루면서 발생

struct MapView: View {
    @EnvironmentObject private var viewModel: MapViewModel
    @State private var showFabAnimation = false

    var body: some View {
        ZStack {
            Map(coordinateRegion: $viewModel.mapRegion,
                showsUserLocation: true, annotationItems: viewModel.places,
                annotationContent: { location in
                MapAnnotation(coordinate: location.coordinates) {
                    PinView(category: location.category)
                        .scaleEffect(viewModel.selectedPlace == location ? 1 : 0.75)
                        .onTapGesture {
                            viewModel.updateSelectedPlace(place: location)
                        }
                }
            })
            .ignoresSafeArea()
            .onAppear {
                viewModel.checkIfLocationServicesIsEnabled()
            }

            fabButton
        }
    }
}

내용

현재 상황에 대해 잘 정리해둔글

MapKit 에서 똑같은 상황을 겪고 있는 사람

스크린샷

chaneeii commented 1 year ago

두개 중 한개를 해치웠다

바인딩으로 넘겨주는 값을 아래와 같이 get set해주었더니 처리가 되었습니다 즉, 새로운 값을 받았을떄 main 에서 넣어준다는 원리

스크린샷 2022-11-20 오전 12 18 50 스크린샷 2022-11-20 오전 12 18 30
chaneeii commented 1 year ago

두번쨰 경고 찾아내기

맵마커 커스텀을 위한 MapAnnotation 을 쓰면 보라색 경고가뜬다 (-> 공식문서도 에러를 낸다,,)

스크린샷 2022-11-20 오전 4 12 19

MapMarker를 쓰면 멀쩡하다

스크린샷 2022-11-20 오전 4 13 32

(진짜.. 이거 또안되면 애플공식문서에 이슈랑 pr 올릴예정)

chaneeii commented 1 year ago
스크린샷 2022-11-20 오전 4 27 54 스크린샷 2022-11-20 오전 4 28 22