Re: [Pyobjc-dev] Using python classes in objc...
Brought to you by:
ronaldoussoren
From: b.bum <bb...@ma...> - 2004-03-10 17:29:21
|
On Mar 10, 2004, at 9:01 AM, Jiva DeVoe wrote: > How do I get around this problem? BBum has mentioned using a factory > method in an abstract superclass. Ok, that's fine, but even then, the > factory method still has to instantiate the python class. How does it > do so without linking the python code? Do something like: @implementation MyFactoryAbstractObjCClassyThing + createAConcreteInstance { Class aClass = NSClassFromString(@"ConcretePythonSubclassOfThisClass"); // only works if you had previously imported the appropriate code in python return [[aClass alloc] init]; } To avoid compiler warnings when messaging the class, you can: - declare the methods on a category of the abstract super. Categories do not have to have an associated implementation. Alternatively, you can provide abstract implementations of the methods that do something like: - (void) methodThatIsReallyImplementedInPython { @throw [NSException exceptionWithName: NSInternalInconsistencyException reason: @"Subclass must implement this." userInfo: nil]; } - use -performSelector:, -performSelector:with: and friends to indirectly invoke the method - make all your functionality Key-Value Coding and use Bindings and/or -setValue:forKey: and -valueForKey: (not really practical for anything but data passing) - use NSInvocation to build up the method invocation I generally go with the first option: @interface Abstract:NSObject + instatiateSubclassNamed: (NSString *) aClassName; @end @interface Abstract(MethodsThatMustBeInPythonSubclass) ... @end Then, in python: class Foo(Abstract) def ....: |