Cali Cali - 1 year ago 126
Objective-C Question

Unknown class name PKPaymentAuthorizationViewControllerDelegate

Xcode error screenshot:

enter image description here

Working environment: Xcode 7.2, iOS 9.0, Mac OS X 10.11.3

I was working on my own Table View Controller to interact with Apple Pay and I copied the sample code from Apple.

In my PaymentTableViewController.swift:

import UIKit
import PassKit
import Contacts

class PaymentTableViewController: UITableViewController, PKPaymentAuthorizationViewControllerDelegate {

But then as it was auto-compiled into Objective-C to "Abletive(My project name)-Swift.h":

@interface PaymentTableViewController : UITableViewController <PKPaymentAuthorizationViewControllerDelegate>

Now and as it should be correct

But it says Unknown class name PKPaymentAuthorizationViewControllerDelegate and Unknown type name PKPaymentAuthorizationStatus instead in the Abletive-Swift.h when I tried to compile and run, apparently this is happening because of Objective-C compatibility right? Because there is no error whatsoever in the Swift code.

My project is currently half Objective-C and Swift.

Answer Source

Add this line to your BridgingHeader.h file

#import <PassKit/PassKit.h>

If you encounter more errors in "YourProjectName-Swift.h" find frameworks in which are classes that causes error and add imports in BridgingHeader.h like

#import <FrameworkInWhichIsClass/FrameworkInWhichIsClass.h>

EDIT: If someone still has problem after including previous in Bridging-Header.h make sure that "Precompile Prefix Header" flag in Build Settings is set to No

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download