0

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.

1 Answers1

1

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]
}
Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278