当前位置:  开发笔记 > IOS > 正文

Cocoa/Objective-C NSProcessInfo怪异

如何解决《Cocoa/Objective-CNSProcessInfo怪异》经验,为你挑选了1个好方法。

所以我刚刚开始深入研究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天真无邪 _



1> epatel..:

这条线

NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);

应该

NSLog(@"Process Name: '%@' Process ID:'%d'", processName, processID);
/*                          change here ^                          */

作为processID仅仅是一个int和无目标C对象


谢谢,我只是测试了它:D我几乎忘记了成为一个n00b的感觉,它有点有趣,有点尴尬......哈哈
推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有