Получение ошибки компиляции
Не - метод @ objc 'paymentAuthorizationViewControllerDidFinish' не удовлетворяет требованию протокола '@objc' PKPaymentAuthorizationViewControllerDelegate '
Если я добавлю @objc до paymentAuthorizationViewControllerDidFinish, то получу новую ошибку
@ objc можно использовать только с членами классов, протоколами @objc и конкретными расширениями классов.
Я могу напрямую расширять Handler с помощью PKPaymentAuthorizationViewControllerDelegate
, но у меня есть два разных класса, расширяющих ApplePayable
, и я не хочу писать одно и то же расширение для другого класса
import UIKit
import PassKit
class ApplePayRequestComposer {}
protocol ApplePayable: PKPaymentAuthorizationViewControllerDelegate {
func applePaymentSheet(composer: ApplePayRequestComposer) -> PKPaymentAuthorizationViewController?
func processPKPayment(payment:PKPayment, completed:@escaping (_ success:Bool)->())
}
extension ApplePayable {
func applePaymentSheet(composer: ApplePayRequestComposer) -> PKPaymentAuthorizationViewController?{
return nil
}
func processPKPayment(payment:PKPayment, completed:@escaping (_ success:Bool)->()) {
completed(false)
}
}
// PKPaymentAuthorizationViewControllerDelegate implementation
extension ApplePayable
{
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: nil)
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Swift.Void) {
processPKPayment(payment: payment) { success in
let status = success ? PKPaymentAuthorizationStatus.success:PKPaymentAuthorizationStatus.failure
let result = PKPaymentAuthorizationResult(status: status, errors: nil)
completion(result)
}
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Swift.Void) {
processPKPayment(payment: payment) { success in
completion(success ? PKPaymentAuthorizationStatus.success: PKPaymentAuthorizationStatus.failure)
}
}
}
class Handler: NSObject, ApplePayable
{
}