简体   繁体   English

更新到 Xcode 13 后出现错误破坏了应用程序

[英]Errors broke app after updating to Xcode 13

I'm working in SwiftUI App Lifecycle.我在 SwiftUI 应用程序生命周期中工作。 I just updated Xcode and am getting a bunch of errors on an app that has been working fine on a slightly older version of Xcode...In AppKitOrUIKitViewControllerLifecycleEvent, I'm getting an error that says 'Missing argument for parameter 'rootView' in call'.我刚刚更新了 Xcode,并在一个应用程序上遇到了一堆错误,该应用程序在稍旧版本的 Xcode 上运行良好...... '。

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

In List++.swift, I'm getting Contextual closure type '(type1,type2) -> RowContent' expects 2 arguments, but 1 was used in closure body.在 List++.swift 中,我得到 Contextual 闭包类型 '(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)
            }
        }
    }
}

On top of all this, I'm getting 'Command CompileSwift failed with a nonzero exit code' error.最重要的是,我收到“Command CompileSwift failed with a nonzero exit code”错误。 AND none of these files are even editable...no clue what to do.而且这些文件都不是可编辑的……不知道该怎么做。 Any help much appreciated.非常感谢任何帮助。

在 Xcode 中转到 -> File然后Packages and Update to Latest Package Versions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM