5

Here is the exact code that I am running on iOS 13.4/Xcode 11.4:

import SwiftUI

struct TestView: View {

    var body: some View {
        VStack() {
            Text("Hello")
        }
        .frame(minWidth: .infinity)
    }
}

struct LoginView_Previews: PreviewProvider {
    static var previews: some View {
        TestView()
    }
}

The crash happens in iOS, so it's hard to get much useful information other than the following:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
#0  0x00007fff2c7cd371 in NSAttributedString.MetricsCache.findMetrics(requestedSize:) ()

Setting minWidth to something other than .infinity fixes the crash, so my question is why is it crashing and should I report it to Apple?

Zorayr
  • 23,770
  • 8
  • 136
  • 129
  • 1
    What are you trying to accomplish? Setting minWIdth to .infinity means the width must be infinite, which is impossible – Lou Franco May 05 '20 at 23:54
  • I was trying to make the frame to be at 100%, then hit this issue, I realized the fix was to use `.maxWidth`, but also wanted to get to the bottom of this crash. – Zorayr May 09 '20 at 18:53
  • Trying to get the view to take up the whole width of the screen. If setting `minWidth: .infinity` isn't the right way to accomplish this it's a clear violation of the principle of least astonishment, and the fact that it _crashes_ is just embarrassing. Setting `maxWidth: .infinity` doesn't make it do what I want in my case. – Robert Atkins May 06 '21 at 08:53

1 Answers1

6

.infinity is an allowed value for a frame's maxWidth NOT for its minWidth it seems.

nine stones
  • 3,264
  • 1
  • 24
  • 36
  • Yeh, wish they had a more easily understood error. Should I report to Apple? – Zorayr May 06 '20 at 02:40
  • I doubt that'll change anything, because `.infinity` is a Float, an otherwise valid parameter for frame sizes. I strongly believe it's a parameter assertion that's throwing here. – nine stones May 06 '20 at 14:27