views:

49

answers:

0

hi, I resently started programming in objc and I was wandering how can I use python code in an existing objc application. I found some threads in this site and some others but they didn't help me at all. What I want to do is to take the SpotlightAPI found in apple's developer website and use the results to process them with python code. Until now, I've done the following:
1. downloaded the SpotlightAPI from apple
2. created a new project based on the cocoa-python application template from PyObjc
3. added the controller files from the SpotlightAPI to the PyObjC
4. Configured the bindings the same way they where in the SpotlightAPI
5. Executed the program and all works successfully
6. created a new python class file which inherits from NSObject (called python.py)
7. the python file has the following code:

from Foundation import *
import objc

NSObject = objc.lookUpClass(u"NSObject")
print "PYTHON VERSION BEING USED:"

class Python(NSObject):
    def sendit_(self, something):
        print something
        return "asdf"


8. I Inserted this code at the beginning of the Controller.m file:

@class Python;

@interface NSObject (MethodsThatReallyDoExist)
-(NSString *) sendit: (id) aString;

@end

@implementation Controller
- (id)init
{
    self = [super init];
    Class pythonClass = NSClassFromString(@"Python");
    myPython = [pythonClass new];
    NSLog(@"Created PythonClass: %@", myPython);
    NSString * oneString = [myPython sendit:@"asdf"];
    NSLog(@"%@", oneString);
    return self;
}


9. added id *myPython; in the variable declarations in the Controller.h file
10. implemented the sendit method in the controller.m file like this:

- (NSString *) sendit:(id) aString
{

    return [myPython sendit:aString];
}


it compiles and runs successfully but the console message I'm getting from the init function is: Created PythonClass: (null) and also the string return of the next log is (null)
anyone knows what am I doing wrong?