0

I reference two frameworks [PDFGenerator and PDFKit] that both contain an object named PDFPage. In the PDFGenerator framework, PDFPage is an Enum. In the PDFKit framework, PDFPage is an object. When I try to create an instance of the PDFPage Enum I get the error:

'PDFPage' is ambiguous for type lookup in this context'.

How do I specify which PDFPage I am trying to instantiate?

Simplified example below:

import PDFKit

import PDFGenerator

public class VC: UIViewController {
    var page:PDFPage? // <-- This throws the error mentioned above.
}
  • Please [search on the error](https://stackoverflow.com/search?q=%5Bswift%5D+is+ambiguous+for+type+lookup+in+this+context) – rmaddy Sep 04 '18 at 05:34
  • you need to called its init method to solve issue using let page = PDFPage() – Hardik Thakkar Sep 04 '18 at 06:06
  • 1
    Have you tried `PDFKit.PDFPage` or `PDFGenerator.PDFPage` ? – OOPer Sep 04 '18 at 06:25
  • As per this article [https://stackoverflow.com/questions/51952394/date-is-ambiguous-for-type-lookup-in-this-context], var page:PDFGenerator.PDFPage should be the answer. The reason this does not work in my example is because in the 'PDFGenerator' framework there is a public class also named 'PDFGenerator'. When I try to declare my variable as page:PDFGenerator.PDFPage it results in the error 'PDFPage' is not a member type of 'PDFGenerator'. Naming a class within a framework the same name as the framework itself may not be a good idea. – Deepak Sreedharan Sep 05 '18 at 00:47

1 Answers1

0

Try this code it will solve error.

import PDFKit
import PDFGenerator

public class ViewController: UIViewController {
    let page = PDFPage() // <-- This solve the error mentioned above.

    override public func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override public func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
Hardik Thakkar
  • 15,269
  • 2
  • 94
  • 81