skip to Main Content

I’m completing the online apple Xcode Tutorial. At the UIKit tutorial portion, I’m repeatedly getting the same error:

 "Type 'PageViewController<Page>' does not conform to protocol 'UIViewControllerRepresentable'"

That portion of the tutorial is a few lines which are copied and pasted:

 struct PageViewController<Page: View>: UIViewControllerRepresentable {
      var pages: [Page]
  }

How can I address this does not conform to protocol.

There are a few Does not conform to protocol errors posts online, each seemingly addressing the same error differently. Clicking fix the error adds this line to the file:

"typealias UIViewControllerType = <#type#>"

Which doesn’t address the issue since the same error occurs.

2

Answers


  1. Chosen as BEST ANSWER

    The additional functions are how Xcode suggested repairing the issue via the error box that appears near the error portion of the code.


  2. You should implement the stubs too, like:

    struct PageViewController<Page: View>: UIViewControllerRepresentable {
        typealias UIViewControllerType = UIViewController // <- Choose the correct controller
    
        func makeUIViewController(context: Context) -> UIViewControllerType {
            // Implement As needed
        }
    
        func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
            // Implement As needed
        }
    
        var pages: [Page]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search