PyObjc Objective C - Python Protocol issue

Issue #240 closed
phanindra surapaneni
created an issue

Hi Ronald,

Thank you very much for PyObjc.

I do have knowledge in iOS swift & Objctive c, but i am new to Python & PyObjc.

By Using PyObjC i did small application in Xcode. Now i am facing an issue with Protocols. Please see below for Sample code.

I have initiated and loaded the objective class from Python using PyObjc

Objective C: (Below is the code i have written in Objective C.

@protocol OBJCDelegate <NSObject>
-(int)triggerService();
@end

@interface MyTestClass

@property (nonatomic, weak) id< OBJCDelegate > objcDelegate;

@end

@implementation MyTestClass

- (id) init {
    if(self = [super init]) {
      [self triggerToPython]
    }
}
- (void) triggerToPython(){
    objcDelegate.triggerService()
}

@end

Now i need to execute the delegate in Python Class.

Python : (Below is my Python class code)

 from pyobjus import autoclass, protocol

    class MyOwnClass():

        def __init__(self):
          print '-> Inside test class'

        def printhello():
           print '-> Hello'
           from pyobjus import autoclass
           MyTestClass = autoclass('MyTestClass')
           cObj = MyTestClass().init()
           cObj.objcDelegate = self    // assiging the delegate here


       @protocol('OBJCDelegate')
       def triggerService(self):
           print '-> delegate triggered'

But it is throwing error as shown below

File "pyobjus/pyobjus.pyx", line 1X, in pyobjus.pyobjus.objc_create_delegate pyobjus.pyobjus.ObjcException: Undeclared protocol OBJCDelegate

Could someone please help me on this.

Thank you.

Comments (6)

  1. Log in to comment