PyObjCを使用してください。
これは後でLeopard &に含まれています。
>>> from Foundation import *
>>> a = NSArray.arrayWithObjects_("a", "b", "c", None)
>>> a
(
a,
b,
c
)
>>> a[1]
'b'
>>> a.objectAtIndex_(1)
'b'
>>> type(a)
<objective-c class NSCFArray at 0x7fff708bc178>
はそれもiPythonで動作します:
は抽象を宣言:
In [1]: from Foundation import *
In [2]: a = NSBundle.allFrameworks()
In [3]: ?a
Type: NSCFArray
Base Class: <objective-c class NSCFArray at 0x1002adf40>
`
は、PythonへのObjective-Cから呼び出すには、最も簡単な方法はにありますObjective-Cのスーパークラス(呼び出したいAPIを含む)
は、クラスの@implementation
サブクラスPythonでクラスのメソッドのスタブ実装を作成し、提供し、具体的な実装
は、具体的なサブクラスのインスタンス
を作成する抽象スーパークラスのファクトリメソッドを作成します
e
@interface Abstract : NSObject
- (unsigned int) foo: (NSString *) aBar;
+ newConcrete;
@end
@implementation Abstract
- (unsigned int) foo: (NSString *) aBar { return 42; }
+ newConcrete { return [[NSClassFromString(@"MyConcrete") new] autorelease]; }
@end
.....
class Concrete(Abstract):
def foo_(self, s): return s.length()
.....
x = [Abstract newFoo];
[x foo: @"bar"];
これはどのように動作しますか。例えば、私は次のように仮定しています: (1)ファイルにPythonコードを入れてくださいConcrete.py (2)Abstract.h/mにobj-cコードを入れてください これを考えると、プログラム? – Fooberman
更新:このチケットの説明があります。[リンク](http://stackoverflow.com/questions/1772491/call-from-objective-c-into-python) – Fooberman
"MyConcrete"の後に閉じ括弧がありませんか? –