Cocoa (GUI) アプリを実行する方法を考え出しました。通常のダブルクリックから、または CLI から。
ダブルクリック (GUI) からアプリを起動すると、2 の引数カウント ( argc ) が返されることに気付きました。
ただし、CLI から起動すると、argcは 1 になります。自分で引数を指定しない限り。
つまり 、if..else..を使用して、アプリがどのように起動されたかを判断できます。
引数を入れる必要がないので、これは私のアプリでは問題なく機能します。
しかし、もっと良い方法はないかと考えました。
main.mのコードの例を次に示します 。
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//This determins if the app is launched from the command line or app itself is opened.
if (argc == 1) {
//app was run from CLI
// Create a object
MyClass *mMyClass;
mMyClass = [[MyClass alloc] init];
// Read the Buffer
[mMyClass readBuffer];
// Write out file on disk
[mMyClass createFile];
[mMyClass doMoreStuff];
[mMyClass release];
mMyClass = nil;
return 0;
} else {
//app was doubled click, (Opened)
return NSApplicationMain(argc, (const char **) argv);
;
// */
// return NSApplicationMain(argc, (const char **) argv);
}
[pool drain];
}
どうもありがとう。M