所以我刚刚开始深入研究Objective-C,Cocoa和iPhone开发.我遇到了一些奇怪的事情,我并没有真正得到这个.
我正在尝试获取进程信息,进程名称工作正常,但当我尝试获取进程ID时,事情变得奇怪.
这是我的代码片段,显然不会向控制台输出任何内容:
NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSString *processName = [processInfo processName]; int processID = [processInfo processIdentifier]; NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);
在此代码块之后,所有其他NSLog调用也将被忽略.并且该过程一直在运行,说明GDB的内容,我在控制台中得到了这个:
Loading program into debugger… GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".Program loaded. sharedlibrary apply-load-rules all Attaching to program: '/Users/jim/Documents/Xcode Projects/CS 193P/Assignment1B (WhatATool)/WhatATool/build/Debug/WhatATool', process 28700. (gdb)
我可能在这里有点白痴,但是嘿,我以前从来没有弄过Objective-C ......哈哈_ _whistles天真无邪 _
这条线
NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);
应该
NSLog(@"Process Name: '%@' Process ID:'%d'", processName, processID); /* change here ^ */
作为processID
仅仅是一个int
和无目标C对象