Note that there are some explanatory texts on larger screens.

plurals
  1. POProxing Python class to Objective-C
    primarykey
    data
    text
    <p>I try to proxy existing Python class to Objective-C. I started from simple sample of Python class:</p> <p><strong>Test.py</strong></p> <pre><code> class Test: def __init__(self): self.text = "" def addText(self, _text): self.text = self.text + _text def addSomeText(self): self.addText("SomeText") </code></pre> <p>Then I wrote Objective-C class for it.</p> <p><strong>ITest.h</strong></p> <pre><code> #import &lt;Cocoa/Cocoa.h&gt; @interface ITest : NSObject - (void) addText: (NSString *)text; - (void) addSomeText; + newTest; @property (nonatomic, assign, getter = _text) NSString *text; @end </code></pre> <p><strong>ITest.m</strong></p> <pre><code> #import "ITest.h" #define ABSTRACT { return nil; } #define ABSTRACT_VOID { } @implementation ITest @dynamic text; - (void) addText: (NSString *)text ABSTRACT_VOID; - (void) addSomeText ABSTRACT_VOID; + newTest { return [[NSClassFromString(@"TestProxy") new] autorelease]; } @end </code></pre> <p>My proxy class (following some articles about PyObjC I subclassing Objective-C class and subclassing original class to access its instance variables):</p> <p><strong>TestProxy.py</strong></p> <pre><code> import Foundation import objc from Test import Test ITest = objc.lookUpClass("ITest") class TestProxy (ITest, Test): # getters/setters def setText_(self, _text): self.text = _text def _text(self): return self.text # methods def addText_(self, text): Test.addText(self, text) def addSomeText(self): Test.addSomeText(self) </code></pre> <p>Now, if I do</p> <p><code>ITest *test = [ITest newTest];</code></p> <p>I always get <code>nil</code> with no warnings or errors in the debug console.</p> <p>If I remove all imports and references to original <code>Test</code> class, I'll get working object. I noticed, that <code>nil</code> will be returned exactly as soon as I add <code>from Test import Test</code>.</p> <p>I think this happens because PyObjC trying to bridge the <code>Test</code> class and fails because its methods do not conform bridge naming rules.</p> <p>Is there a way to say PyObjC not to do so? Or, maybe, all stuff I did is wrong and there is a better way to translate existing Python stuff to Objective-C?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload