From 9539803d745e7545840ea101395d5234375e5d1b Mon Sep 17 00:00:00 2001 From: alexandrev-tibco Date: Thu, 23 Jul 2026 11:02:56 +0200 Subject: [PATCH] Fix crash al abrir Import Data en Mac Catalyst (@EnvironmentObject no heredado en sheets) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ImportDataView usa @EnvironmentObject (iapService/accountStore/tabSelection). En Mac (Designed for iPad) las sheets no heredan el environment vía PresentationHostingController → EnvironmentObject.error() / SIGTRAP al abrir Import Data (ImportDataView.swift:247, shouldShowAccountSelection). Reinyectados los 3 objects en las sheets de Settings, Dashboard y Onboarding. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01L2p3gUZRNWW388rWFRjiU7 --- PortfolioJournal/Views/Dashboard/DashboardView.swift | 6 ++++++ PortfolioJournal/Views/Onboarding/OnboardingView.swift | 9 +++++++++ PortfolioJournal/Views/Settings/SettingsView.swift | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/PortfolioJournal/Views/Dashboard/DashboardView.swift b/PortfolioJournal/Views/Dashboard/DashboardView.swift index 807dfd2..3c13d03 100644 --- a/PortfolioJournal/Views/Dashboard/DashboardView.swift +++ b/PortfolioJournal/Views/Dashboard/DashboardView.swift @@ -6,6 +6,7 @@ import TipKit struct DashboardView: View { @EnvironmentObject var iapService: IAPService @EnvironmentObject var accountStore: AccountStore + @EnvironmentObject var tabSelection: TabSelectionStore @StateObject private var viewModel: DashboardViewModel @StateObject private var goalsViewModel = GoalsViewModel() @State private var showingImport = false @@ -110,7 +111,12 @@ struct DashboardView: View { goalsViewModel.refresh() } .sheet(isPresented: $showingImport) { + // Re-inject env objects: sheets don't inherit @EnvironmentObject on + // Mac Catalyst (Designed for iPad) → ImportDataView crashed on open. ImportDataView() + .environmentObject(iapService) + .environmentObject(accountStore) + .environmentObject(tabSelection) } .sheet(isPresented: $showingAddSource) { AddSourceView() diff --git a/PortfolioJournal/Views/Onboarding/OnboardingView.swift b/PortfolioJournal/Views/Onboarding/OnboardingView.swift index 8595044..370ce08 100644 --- a/PortfolioJournal/Views/Onboarding/OnboardingView.swift +++ b/PortfolioJournal/Views/Onboarding/OnboardingView.swift @@ -13,6 +13,12 @@ struct OnboardingView: View { @State private var showingImportSheet = false @State private var showingAddSource = false + // Forwarded into the ImportDataView sheet — sheets don't inherit + // @EnvironmentObject on Mac Catalyst, which crashed the import screen. + @EnvironmentObject private var iapService: IAPService + @EnvironmentObject private var accountStore: AccountStore + @EnvironmentObject private var tabSelection: TabSelectionStore + private let pages: [OnboardingPage] = [ OnboardingPage( icon: "chart.line.uptrend.xyaxis", @@ -123,6 +129,9 @@ struct OnboardingView: View { } .sheet(isPresented: $showingImportSheet) { ImportDataView(importContext: .onboarding) + .environmentObject(iapService) + .environmentObject(accountStore) + .environmentObject(tabSelection) } .sheet(isPresented: $showingAddSource) { AddSourceView() diff --git a/PortfolioJournal/Views/Settings/SettingsView.swift b/PortfolioJournal/Views/Settings/SettingsView.swift index d57cbec..ec1f85b 100644 --- a/PortfolioJournal/Views/Settings/SettingsView.swift +++ b/PortfolioJournal/Views/Settings/SettingsView.swift @@ -6,6 +6,8 @@ struct SettingsView: View { private let iapService: IAPService @StateObject private var viewModel: SettingsViewModel @EnvironmentObject private var adMobService: AdMobService + @EnvironmentObject private var accountStore: AccountStore + @EnvironmentObject private var tabSelection: TabSelectionStore @AppStorage("showForecast") private var showForecast = true @AppStorage("cloudSyncEnabled") private var cloudSyncEnabled = false @AppStorage("faceIdEnabled") private var faceIdEnabled = false @@ -86,7 +88,11 @@ struct SettingsView: View { ActivityView(activityItems: [shareItem.url]) } .sheet(isPresented: $viewModel.showingImportSheet) { + // Sheets don't inherit @EnvironmentObject on Mac Catalyst → re-inject. ImportDataView() + .environmentObject(iapService) + .environmentObject(accountStore) + .environmentObject(tabSelection) } .confirmationDialog( "Reset All Data",