Cocoa (Obj-C) with Java or Python

Discussion in 'Mac Programming' started by laptin, Sep 27, 2007.

  1. laptin macrumors newbie

    Joined:
    Sep 27, 2007
    #1
    Hi,

    I was wondering how can you call java APIs or python APIs (either one) in Objective-C?

    I know you could do this in cocoa:

    id MyJavaClass = NSClassFromString(@"java.util.Vector");
    id vector = [[MyJavaClass alloc] init];
    [vector add:mad:"one item!"];
    NSLog(@"item 1=%@", [vector get:0]);
    [vector release];

    this prints "item 1=one item!" in console, but that's it.
    Does anyone has other examples? Like how to pass in arguments to a java constructor, like so:

    id MyStringClass = NSClassFromString(@"java.lang.String");
    id mystr = [[MyStringClass alloc] init:mad:"Hello World"];

    But this does not work, i do not know why.

    Any help is appreciated.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    For Python, you could check out the PyObjC project. For calling Java from Cocoa, check out this page.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    You can also call Python or Java from a Cocoa application using NSTask. Use NSFileHandle and NSPipe if you need to communicate with that process as it runs. AppleScript is also an option but probably not what you want here.
     

Share This Page