Re: [Pyobjc-dev] Using python classes in objc...
Brought to you by:
ronaldoussoren
From: Jiva D. <ji...@de...> - 2004-03-10 17:41:48
|
That is exactly what I was looking for! Thank you so much! On Mar 10, 2004, at 10:19 AM, b.bum wrote: > 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 ....: > > -- Jiva DeVoe jiva at devoesquared.com http://www.devoesquared.com |