0

I'm working with obj-C app, I need to integrate Clover Payment which are swift protocols. I have installed clover pods from https://github.com/clover/remote-pay-ios

how to use swift protocols in obj-C? I have done this:

In obj-C .h file

    @class ICloverConnector;
    @interface ViewPayment: UIViewController
    {
         ICloverConnector *cc;
    } 

In obj-C .m file

    #import "ProjectName-Swift.h"

In ICloverConnector.swift

public protocol ICloverConnector : AnyObject {
    
     func addCloverConnectorListener(_ cloverConnectorListener:ICloverConnectorListener) -> Void
    
    
    func initializeConnection() -> Void
    
}

How do I call these two functions from Obj-C class ?

Honey
  • 2,840
  • 11
  • 37
  • 71
  • 4
    There are no Swift classes in your question. You've shown a Swift _protocol_. If you want to use that in Objective-C, mark it as `@objc`. – Sweeper Jul 19 '21 at 07:03
  • Adding @objc before that gets error : Method cannot be marked "@objc" because the type of the parameter cannot be represented in Objective-C. – Honey Jul 19 '21 at 07:09
  • You will need to create obj-c wrappers – Cy-4AH Jul 19 '21 at 08:01
  • @Cy-4AH Plz let me know how can we do it – Honey Jul 19 '21 at 09:03
  • @Sweeper Adding objc before it shows error as "Method cannot be marked as objc because the type of the parameter cannot be represented in Objective-C – Honey Jul 19 '21 at 10:05
  • Also Exchange `AnyObject` with `NSObject`, which is not perfect but should work. Because it is more similar to objc's `id`. Or write the protocol in objc, then its more obvious that this pod is exposing the framework to objc but not the classes. If you like remind them to correct that with an issue in github – Ol Sen Jul 19 '21 at 10:38
  • @Honey write special code with `@objc` markers – Cy-4AH Jul 19 '21 at 11:56
  • @Cy-4AH I have used wrappers , but it shows error : Method cannot be marked "@objc" because the type of the parameter cannot be represented in Objective-C – Honey Jul 20 '21 at 10:58
  • No it isn't wrappers, you just added `@objc`. You need created type that wraps that type that can't be represented in objc and create method that wrapt method that can't be marked. – Cy-4AH Jul 21 '21 at 06:38
  • @Cy-4AH Can u plz share any link that shows what you are trying to explain – Honey Jul 22 '21 at 04:45
  • Honey you need a forward declaration @protocol MySwiftProtocol; see my answer below – SeaSpell Jul 28 '21 at 22:28

1 Answers1

0

You need to use forward declarations. See here:

https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

SeaSpell
  • 678
  • 3
  • 9