更新到Xcode 13后导致应用程序崩溃



我在SwiftUI应用程序生命周期工作。我刚刚更新了Xcode,并在一个应用程序上得到了一堆错误,这个应用程序在稍微老一点的Xcode版本上工作得很好……我得到一个错误,在AppKitOrUIKitViewControllerLifecycleEvent说,"失踪的理由参数"rootView在呼叫。

import Swift
import SwiftUI
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
public enum AppKitOrUIKitViewControllerLifecycleEvent {
case didLoad
case willAppear
case didAppear
case willDisappear
case didDisappear
case layoutSubviews
}
struct _AppKitOrUIKitViewControllerLifecycleEventView<Content: View>: UIViewControllerRepresentable {
struct Callbacks {
var onDidLoad: ((UIViewController) -> Void)?
var onWillAppear: ((UIViewController) -> Void)?
var onDidAppear: ((UIViewController) -> Void)?
var onWillDisappear: ((UIViewController) -> Void)?
var onDidDisappear: ((UIViewController) -> Void)?
var onWillLayoutSubviews: ((UIViewController) -> Void)?
var onLayoutSubviews: ((UIViewController) -> Void)?

mutating func setCallback(
_ callback: ((UIViewController) -> Void)?,
for event: AppKitOrUIKitViewControllerLifecycleEvent
) {
switch event {
case .didLoad:
self.onDidLoad = callback
case .willAppear:
self.onWillAppear = callback
case .didAppear:
self.onDidAppear = callback
case .willDisappear:
self.onWillDisappear = callback
case .didDisappear:
self.onDidDisappear = callback
case .layoutSubviews:
self.onLayoutSubviews = callback
}
}
}

class UIViewControllerType: UIHostingController<Content> {
var callbacks: Callbacks?

override func viewDidLoad() {
super.viewDidLoad()

callbacks?.onDidLoad?(self)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

callbacks?.onWillAppear?(self)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

callbacks?.onDidAppear?(self)
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

callbacks?.onWillDisappear?(self)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

callbacks?.onDidDisappear?(self)
}

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

callbacks?.onWillLayoutSubviews?(self)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

callbacks?.onLayoutSubviews?(self)
}
}

func makeUIViewController(context: Context) -> UIViewControllerType {
UIViewControllerType() //root error view here
}

func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {

}
}
#endif

在list++ .swift中,我得到上下文闭包类型'(type1,type2) ->RowContent'需要2个参数,但是在闭包正文中使用了1个参数。

import Swift
import SwiftUI
extension List {
@available(watchOS, unavailable)
public init<Data: RandomAccessCollection, RowContent: View>(
_ data: Data,
selection: Binding<Set<SelectionValue>>,
@ViewBuilder rowContent: @escaping (Data.Element, _ isSelected: Bool) -> RowContent
) where Data.Element: Identifiable, Content == ForEach<Data, Data.Element.ID, HStack<RowContent>>, SelectionValue == Data.Element.ID {
self.init(data, selection: selection, rowContent: { element in //here this error appears
rowContent(element, selection.wrappedValue.contains(element.id))
})
}

@available(watchOS, unavailable)
public init<Data: RandomAccessCollection, RowContent: View>(
_ data: Data,
selection: Binding<Set<SelectionValue>>,
@ViewBuilder rowContent: @escaping (Data.Element, _ isSelected: Bool) -> RowContent
) where Data.Element: Identifiable, Content == ForEach<Data, Data.Element.ID, HStack<RowContent>>, SelectionValue == Data.Element {
self.init(data, selection: selection, rowContent: { element in //here the error also appears
rowContent(element, selection.wrappedValue.contains(element))
})
}
}
extension List where SelectionValue == Never {
@available(watchOS, unavailable)
public init<Data: MutableCollection & RandomAccessCollection, RowContent: View>(
_ data: Binding<Data>,
@ViewBuilder rowContent: @escaping (Binding<Data.Element>) -> RowContent
) where Data.Element: Identifiable, Content == ForEach<AnyRandomAccessCollection<_IdentifiableElementOffsetPair<Data.Element, Data.Index>>, Data.Element.ID, RowContent> {
self.init {
ForEach(data) { (element: Binding<Data.Element>) -> RowContent in
rowContent(element)
}
}
}
}

最重要的是,我得到'Command compilesswift failed with an non - zero exit code'错误。而且这些文件都不能编辑…不知道该怎么做。如有任何帮助,不胜感激。

在Xcode中进入->File包然后更新到最新的包版本.

最新更新