![](/img/trans.png)
[英]Why does my SwiftUI app crash when navigating backwards after placing a `NavigationLink` inside of a `navigationBarItems` in a `NavigationView`?
[英]Why does a second @State variable crash my program in SwiftUI
import SwiftUI
import CoreData
struct AddTaskView: View {
@Environment(\.managedObjectContext) private var viewContext
@Environment(\.presentationMode) var presentationMode
@FetchRequest(entity: Task.entity(), sortDescriptors: [])
var tasks: FetchedResults<Task>
@FetchRequest(entity: DailyScore.entity(), sortDescriptors: [NSSortDescriptor(key: "date", ascending: false)])
var scores: FetchedResults<DailyScore>
let types = ["Exercise", "German", "Cold Shower", "Fast Food"]
@State var selectedTaskIndex = 0
@State var newType = ""
var body: some View {
我不明白为什么@State var newType = ""
会导致程序崩溃。 (并且它与使用无关,因此据我所知这无关紧要)
更新:这似乎只是一个 Xcode 错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.