Hello,
I am fairly new to Swift development and I'm encountering a live crash that I can't figure out. Any pointers on how to even figure this one out would be appreciated because I can't reproduce the bug locally.
A simplified version of my code looks like this:
And the only place where I call this view is here in my SettingsView:
and in my string file I have:
Finally here is the data from crashlytics:
I've then tried to change the code to pass a String, but I'm getting the exact same crash.
It was later pointed out to me that it could be related to UINavigationItem setLargeTitleDisplayMode.
Here is what I do in the SettingsView:
In context, it's more or less:
In my ContentView I have the following things in my init call:
I am fairly new to Swift development and I'm encountering a live crash that I can't figure out. Any pointers on how to even figure this one out would be appreciated because I can't reproduce the bug locally.
A simplified version of my code looks like this:
Code Block swiftstruct LinkItem: View { var content: LocalizedStringKey // This is the line crashing (SettingsView.swift:7) var body: some View { Text(content) }}
And the only place where I call this view is here in my SettingsView:
Code Block swiftLinkItem(content: "settings.tos")LinkItem(content: "settings.pp")LinkItem(content: "settings.sc")
and in my string file I have:
Code Block "settings.tos" = "Terms of service";"settings.pp" = "Privacy policy";"settings.sc" = "Support & contact";
Finally here is the data from crashlytics:
Code Block Crashed: com.apple.main-thread0 SwiftUI 0x1bde98bd0 ViewRendererHost.render(interval:updateDisplayList:) + 5601 SwiftUI 0x1be003f94 _UIHostingView.layoutSubviews() + 1682 SwiftUI 0x1be003fc0 @objc _UIHostingView.layoutSubviews() + 243 UIKitCore 0x18b6a73d0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 21404 QuartzCore 0x18dc0a7dc -[CALayer layoutSublayers] + 2845 QuartzCore 0x18dc10958 CA::Layer::layout_if_needed(CA::Transaction*) + 4806 UIKitCore 0x18b693684 -[UIView(Hierarchy) layoutBelowIfNeeded] + 5367 UIKitCore 0x18ab69358 -[UINavigationController _layoutViewController:] + 11888 UIKitCore 0x18ab63210 -[UINavigationController _layoutTopViewControllerLookForNested:] + 6049 UIKitCore 0x18ab65074 -[UINavigationController _performWhileIgnoringUpdateTopViewFramesToMatchScrollOffset:] + 4810 UIKitCore 0x18ab652f8 -[UINavigationController _performTopViewGeometryUpdates:] + 11211 UIKitCore 0x18ab651c4 -[UINavigationController _updateTopViewFramesToMatchScrollOffsetInViewController:contentScrollView:topLayoutType:] + 24412 UIKitCore 0x18ab64e14 -[UINavigationController _updateTopViewFramesForViewController:isCancelledTransition:isOrientationChange:] + 23613 UIKitCore 0x18ab725b8 -[UINavigationController _navigationBarChangedSize:] + 39214 UIKitCore 0x18a91fdf0 -[UINavigationBar _sendNavigationBarResize] + 7615 UIKitCore 0x18a9689d8 -[_UINavigationBarVisualProviderModernIOS changeLayout] + 8016 UIKitCore 0x18a9714f8 -[_UINavigationBarVisualProviderModernIOS navigationItemUpdatedLargeTitleDisplayMode:] + 18017 UIKitCore 0x18a9246b0 -[UINavigationItem setLargeTitleDisplayMode:] + 6418 SwiftUI 0x1bdd0cf48 UINavigationItem.update(using:environment:navController:) + 32019 SwiftUI 0x1bdb02d78 UIKitNavigationBridge.preferencesDidChange(_:) + 54420 SwiftUI 0x1bda979d0 _UIHostingView.preferencesDidChange() + 43621 SwiftUI 0x1bdb82e60 ViewGraph.updateOutputs(at:) + 17622 SwiftUI 0x1bdea3844 closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 96023 SwiftUI 0x1bdea32ac closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 57624 SwiftUI 0x1bde98b30 ViewRendererHost.render(interval:updateDisplayList:) + 40025 SwiftUI 0x1be003f94 _UIHostingView.layoutSubviews() + 16826 SwiftUI 0x1be003fc0 @objc _UIHostingView.layoutSubviews() + 2427 UIKitCore 0x18b6a73d0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 214028 QuartzCore 0x18dc0a7dc -[CALayer layoutSublayers] + 28429 QuartzCore 0x18dc10958 CA::Layer::layout_if_needed(CA::Transaction*) + 48030 QuartzCore 0x18dc1b578 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 13631 QuartzCore 0x18db63f1c CA::Context::commit_transaction(CA::Transaction*, double) + 30432 QuartzCore 0x18db8dc08 CA::Transaction::commit() + 67633 UIKitCore 0x18b228e58 34-[UIApplication _firstCommitBlock]_block_invoke_2 + 8034 CoreFoundation 0x18711c834 CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 2035 CoreFoundation 0x18711bfd4 CFRunLoopDoBlocks + 26436 CoreFoundation 0x187117250 __CFRunLoopRun + 110037 CoreFoundation 0x187116adc CFRunLoopRunSpecific + 46438 GraphicsServices 0x19109c328 GSEventRunModal + 10439 UIKitCore 0x18b211ae0 UIApplicationMain + 193640 MY APP 0x1041b6de4 main + 7 (SettingsView.swift:7)41 libdyld.dylib 0x186fa0360 start + 4
I've then tried to change the code to pass a String, but I'm getting the exact same crash.
Code Block swiftstruct LinkItem: View { var content: String var body: some View { Text( NSLocalizedString(content, comment: "")) }}
It was later pointed out to me that it could be related to UINavigationItem setLargeTitleDisplayMode.
Here is what I do in the SettingsView:
Code Block .navigationBarTitle(Text("settings.title"), displayMode: .inline)
In context, it's more or less:
Code Block swiftvar body: some View { NavigationView { VStack(alignment: .leading){ // Most content }..navigationBarTitle(Text("settings.title"), displayMode: .inline) }}
In my ContentView I have the following things in my init call:
Code Block swiftinit() { UINavigationBar.appearance().isTranslucent = false UINavigationBar.appearance().titleTextAttributes = [ .foregroundColor: Color.appDark.uiColor(), .font : UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.bold) ]}