SwiftUI @Observable에 클로저를 저장하면 EXC_BAD_ACCESS가 발생하는 이유

뭘 하려고 했냐면 iOS 음악 스트리밍 앱을 만들고 있었는데요. NavigationDestination으로 이동하는 상세 화면마다 ViewModel을 두고, API 호출 로직을 클로저로 주입하는 구조를 쓰고 있었어요. 대충 이런 식이었거든요: @Observable final class PlaylistDetailVM { var songs: [Song] = [] var isLoading = false // API 클라이언트의 메서드를 클로저로 주입 private let fetchSongs: (String) async throws -> [Song] private let addToPlaylist: (String, [String]) async throws -> Void init( fetchSongs: @escaping (String) async throws -> [Song], addToPlaylist: @escaping (String, [String]) async throws -> Void ) { self.fetchSongs = fetchSongs self.addToPlaylist = addToPlaylist } } NavigationDestination에서 @State로 VM을 생성하고요: ...

2026년 4월 21일 · 3 분 · Young