Xcode 13.2.1 - Simulator works, Preview doesn't

Curious to know if anyone understands why I'm getting the following error

"Cannot preview in this file" - [appname] crashed"

Running the code on my (wirelessly) attached iPhone XR works, but the in-Xcode Preview window doesn't.

Here's the log produced by the Diagnostics option: <Well, I tried to attach the zip file created from the previews-diagnostics-##-## folder, but this text field wouldn't accept that file type. Is there a particular file within the folder that I should upload instead?>

Here's the code from the ContentView file for my (very basic) project:

	
import SwiftUI

struct ContentView: View {

	@FocusState private var amountIsFocused: Bool
	
	@State private var checkAmount = 0.0
	@State private var numberOfPeople = 0
	@State private var tipPercentage = 0
	
	let tipPercentages = [0, 10, 15, 20, 25]
	
	var totalPerPerson: Double {
		let peopleCount = Double(numberOfPeople + 2)
		let tipSelection = Double(tipPercentage)
		
		let tipValue = tipSelection / 100 * checkAmount
		let grandTotal = checkAmount + tipValue
		let amountPerPerson = grandTotal / peopleCount
		
		return amountPerPerson
	}

	var totalAmount: Double {
		let tipSelection = Double(tipPercentage)
		
		let tipValue = tipSelection / 100 * checkAmount
		let grandTotal = checkAmount + tipValue
		
		return grandTotal
	}

	var body: some View {
		NavigationView {
			Form {
				Section {
					TextField("Amount", value: $checkAmount, format: .currency(code: Locale.current.currencyCode ?? "USD"))
						.keyboardType(.decimalPad)
						.focused($amountIsFocused)
					
					Picker("Number of people", selection: $numberOfPeople) {
						ForEach(2 ..< 100) {
							Text("\($0) people")
						}
					}
				}
				
				Section {
					Picker("Tip percentage", selection: $tipPercentage) {
						ForEach(0 ..< 101) {
							Text($0, format: .percent)
						}
					}
				} header: {
					Text("Select tip percentage")
					
				}
				
				Section {
					Text("Grand total: \(totalAmount, format: .currency(code: Locale.current.currencyCode ?? "USD"))")
				}
				
				Section {
					Text(totalPerPerson, format: .currency(code: Locale.current.currencyCode ?? "USD"))
				} header: {
					Text("Amount per person")
				}
				
				.navigationTitle("WeSplit")
				.navigationBarTitleDisplayMode(.inline)
			}
			
			.toolbar {
				ToolbarItemGroup(placement: .keyboard) {
					Spacer()
					Button("Done") {
						amountIsFocused = false
					}
				}
			}
		}
	}
}

struct ContentView_Previews: PreviewProvider {
	static var previews: some View {
		ContentView()
	}
}

does the crash still reproduce if you remove the usage of @FocusState?

I got my previews to work again by going to 'Editor'--->'Canvas'--->and unchecking 'Automatically Refresh Canvas'.

However, I still haven't been able to get my simulator to work since updating to Xcode 13.2.1.

The same problem happens to me after updating Xcode and building a project for iMac maybe. Apple devs working on it check this : discussion

I get this same issue when using @FocusState. If I remove it from the view then the preview works; re-adding it causes the preview to crash.

Right now is not working preview M1 Xcode. I cofirm

Xcode 13.2.1 - Simulator works, Preview doesn't
 
 
Q