I have a simple widget with a LazyVStack containing a foreach. The preview crashes, but when I run the widget on device it works.
I get the following error when trying to use LazyVStack.
I can simply change the LazyVStack to a VStack and the preview works.
My code looks like this:
I get the following error when trying to use LazyVStack.
Code Block RemoteHumanReadableError: Failed to update preview. The preview process appears to have crashed. Error encountered when sending 'fetchTimeline' message to agent. ================================== | RemoteHumanReadableError: The operation couldn’t be completed. (BSServiceConnectionErrorDomain error 3.) | | BSServiceConnectionErrorDomain (3): | ==BSErrorCodeDescription: OperationFailed
I can simply change the LazyVStack to a VStack and the preview works.
My code looks like this:
Code Block struct MediumMarketsWidgetView: View { let tokenContracts: [TokenContract] var body: some View { LazyVStack { ForEach(tokenContracts) { tokenContract in HStack { VStack(alignment: .leading) { Text(tokenContract.symbol.name) .font(Font.caption.smallCaps().weight(.bold)) Text(tokenContract.name) .font(Font.caption2) } Spacer() VStack(alignment: .trailing) { Text(tokenContract.currencyRateFormatted()) .font(Font.caption.smallCaps().weight(.bold)) Text(tokenContract.priceChangePercentFormatted() ?? "%0.00") .font(Font.caption2.weight(.bold)) .foregroundColor(Color(tokenContract.priceChangePercent ?? Double.zero < 0 ? "Danger" : "Success")) } } .foregroundColor(.white) } } .padding(16) } }