Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

laptin

macrumors newbie
Original poster
Sep 27, 2007
3
0
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.