Home / IOS Development / ios – LocalizedStringKey crashes with SwiftUI

ios – LocalizedStringKey crashes with SwiftUI



7;m pretty new to the Swift development, and I’m experiencing a live crash that I can not figure out. Any tips on how to even figure this out will be appreciated because I can not reproduce the error locally.

A simplified version of my code looks like this:

struct LinkItem: View {
    var content: LocalizedStringKey // This is the line crashing (SettingsView.swift:7)
    
    var body: some View {
        Text(content)
    }
}

And the only place I call this sight is here in mine SettingsView:

LinkItem(content: "settings.tos")
LinkItem(content: "settings.pp")
LinkItem(content: "settings.sc")

and in my string file I have:

"settings.tos" = "Terms of service";
"settings.pp" = "Privacy policy";
"settings.sc" = "Support & contact";

Finally here is the data from crashlytics:

Crashed: com.apple.main-thread
0  SwiftUI                        0x1bde98bd0 ViewRendererHost.render(interval:updateDisplayList:) + 560
1  SwiftUI                        0x1be003f94 _UIHostingView.layoutSubviews() + 168
2  SwiftUI                        0x1be003fc0 @objc _UIHostingView.layoutSubviews() + 24
3  UIKitCore                      0x18b6a73d0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2140
4  QuartzCore                     0x18dc0a7dc -[CALayer layoutSublayers] + 284
5  QuartzCore                     0x18dc10958 CA::Layer::layout_if_needed(CA::Transaction*) + 480
6  UIKitCore                      0x18b693684 -[UIView(Hierarchy) layoutBelowIfNeeded] + 536
7  UIKitCore                      0x18ab69358 -[UINavigationController _layoutViewController:] + 1188
8  UIKitCore                      0x18ab63210 -[UINavigationController _layoutTopViewControllerLookForNested:] + 604
9  UIKitCore                      0x18ab65074 -[UINavigationController _performWhileIgnoringUpdateTopViewFramesToMatchScrollOffset:] + 48
10 UIKitCore                      0x18ab652f8 -[UINavigationController _performTopViewGeometryUpdates:] + 112
11 UIKitCore                      0x18ab651c4 -[UINavigationController _updateTopViewFramesToMatchScrollOffsetInViewController:contentScrollView:topLayoutType:] + 244
12 UIKitCore                      0x18ab64e14 -[UINavigationController _updateTopViewFramesForViewController:isCancelledTransition:isOrientationChange:] + 236
13 UIKitCore                      0x18ab725b8 -[UINavigationController _navigationBarChangedSize:] + 392
14 UIKitCore                      0x18a91fdf0 -[UINavigationBar _sendNavigationBarResize] + 76
15 UIKitCore                      0x18a9689d8 -[_UINavigationBarVisualProviderModernIOS changeLayout] + 80
16 UIKitCore                      0x18a9714f8 -[_UINavigationBarVisualProviderModernIOS navigationItemUpdatedLargeTitleDisplayMode:] + 180
17 UIKitCore                      0x18a9246b0 -[UINavigationItem setLargeTitleDisplayMode:] + 64
18 SwiftUI                        0x1bdd0cf48 UINavigationItem.update(using:environment:navController:) + 320
19 SwiftUI                        0x1bdb02d78 UIKitNavigationBridge.preferencesDidChange(_:) + 544
20 SwiftUI                        0x1bda979d0 _UIHostingView.preferencesDidChange() + 436
21 SwiftUI                        0x1bdb82e60 ViewGraph.updateOutputs(at:) + 176
22 SwiftUI                        0x1bdea3844 closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 960
23 SwiftUI                        0x1bdea32ac closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 576
24 SwiftUI                        0x1bde98b30 ViewRendererHost.render(interval:updateDisplayList:) + 400
25 SwiftUI                        0x1be003f94 _UIHostingView.layoutSubviews() + 168
26 SwiftUI                        0x1be003fc0 @objc _UIHostingView.layoutSubviews() + 24
27 UIKitCore                      0x18b6a73d0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2140
28 QuartzCore                     0x18dc0a7dc -[CALayer layoutSublayers] + 284
29 QuartzCore                     0x18dc10958 CA::Layer::layout_if_needed(CA::Transaction*) + 480
30 QuartzCore                     0x18dc1b578 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 136
31 QuartzCore                     0x18db63f1c CA::Context::commit_transaction(CA::Transaction*, double) + 304
32 QuartzCore                     0x18db8dc08 CA::Transaction::commit() + 676
33 UIKitCore                      0x18b228e58 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 80
34 CoreFoundation                 0x18711c834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
35 CoreFoundation                 0x18711bfd4 __CFRunLoopDoBlocks + 264
36 CoreFoundation                 0x187117250 __CFRunLoopRun + 1100
37 CoreFoundation                 0x187116adc CFRunLoopRunSpecific + 464
38 GraphicsServices               0x19109c328 GSEventRunModal + 104
39 UIKitCore                      0x18b211ae0 UIApplicationMain + 1936
40 MY APP                         0x1041b6de4 main + 7 (SettingsView.swift:7)
41 libdyld.dylib                  0x186fa0360 start + 4

I then tried to change the code to send a string, but I get the exact same crash.

struct LinkItem: View {
    var content: String

    var body: some View {
        Text( NSLocalizedString(content, comment: ""))
    }
}


Source link