1

I'm working in SwiftUI App Lifecycle. 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'.

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.

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. AND none of these files are even editable...no clue what to do. Any help much appreciated.

koen
  • 5,383
  • 7
  • 50
  • 89
nickcoding2
  • 142
  • 1
  • 8
  • 34
  • 1
    Which lines are the errors on? – aheze Oct 07 '21 at 01:00
  • 1
    @aheze added comments to lines with errors, sorry about that – nickcoding2 Oct 07 '21 at 01:01
  • 1
    Not sure if related, but you have `onWillLayoutSubviews` in your callbacks, but the corresponding case is missing from the enum. Which version of Xcode is the "slightly older version" ? – koen Oct 07 '21 at 02:00
  • @koen I believe I was working on an Xcode 12 (I'd imagine the last one that released this summer). That being said, I made this app back in march. Still, not sure how to transfer all this to XC13 but it seems pretty dumb that isn't not backwards compatible with an app I made a half year ago... – nickcoding2 Oct 07 '21 at 02:39
  • 1
    If you are not able to make it work in Xcode13, you can download Xcode12, and use it to build the app while working on fixing the errors in Xcode13 (this assumes you keep the two Xcode installations side by side). – Cristik Oct 07 '21 at 05:48
  • @Cristik Yep, that's what I did, but still these files in XC13 aren't even editable...so I have no clue how to make my app XC13 compatible. – nickcoding2 Oct 07 '21 at 11:39
  • 1
    What is the origin of the files that are not editable, are they yours? – koen Oct 07 '21 at 12:03
  • @koen No, as far as I can tell they are built in files made when the project was created. What's strange is that I looked up the file name on google and literally 0 search results came up. Names are listed above each code block. – nickcoding2 Oct 07 '21 at 12:11
  • 1
    The `UIHostingController` is an easy one `rootView` [is a requirement](https://developer.apple.com/documentation/swiftui/uihostingcontroller) and easy to add. But the others use un documented initializers so they were likely never guaranteed to work. It might be an optimization since for the first 2 `List` `init` `rowContent` needs a `Bool` – lorem ipsum Oct 07 '21 at 12:57
  • 1
    'Command CompileSwift failed with a nonzero exit code' is often the final error in a chain of more errors. What other errors do you get besides the ones listed above ? Did you try a Clean Build (Cmd Shift K)? – koen Oct 07 '21 at 15:57
  • Also, there are many posts in SO with that CompileSwift error, maybe one of them can point you in the right direction. – koen Oct 07 '21 at 15:59
  • @koen Yeah, I did all the basic stuff, cleaned, cleared Xcode cache, uninstalled/reinstalled pods (thought maybe compatibility issue w pods, but doubtful because they should all be backwards compatible, right?), ended up downgrading to Xcode 12.5 and am hoping that next time I try to update it'll not throw a bajillion errors. – nickcoding2 Oct 07 '21 at 18:22
  • @loremipsum Still, these files have to change for the code to compile, how can I change them? – nickcoding2 Oct 07 '21 at 19:27

1 Answers1

1

In Xcode go to ->File then Packages and Update to Latest Package Versions.

Muneeb
  • 11
  • 3