Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何检查NSLog输出?_Iphone_Objective C_Ios_Nslog - Fatal编程技术网

Iphone 如何检查NSLog输出?

Iphone 如何检查NSLog输出?,iphone,objective-c,ios,nslog,Iphone,Objective C,Ios,Nslog,我想检查一些字符串的NSLog() 是否有一种方法可以检查NSLog语句的输出长度或从中创建字符串?这是一个概念证明,而不是一个实际的解决方案,因此可以将最佳实践问题放在一边。尝试检查长度: NSLog(@"%i",[string length]); int len = [myString length]; if(len == 0){ NSLog(@"String is empty"); } else{ NSLog(@"String is : %@", myString); }

我想检查一些字符串的
NSLog()


是否有一种方法可以检查
NSLog
语句的输出长度或从中创建字符串?这是一个概念证明,而不是一个实际的解决方案,因此可以将最佳实践问题放在一边。

尝试检查长度:

NSLog(@"%i",[string length]);

int len = [myString length];
if(len == 0){
   NSLog(@"String is empty");
}
else{
  NSLog(@"String is : %@", myString);
}

如果要检查字符串是否为空,请尝试:

if ((NSNull *)string != [NSNull null]){

}

您可能需要将
NSLog()
输出重定向到文件。请看一看“”

这只会影响来自应用程序的
NSLog()
调用

int fd = creat ("/Users/parag/Desktop/my_log", S_IRUSR | S_IWUSR | S_IRGRP |
S_IROTH);
close (STDERR_FILENO);
dup (fd);
close (fd);
NSLog(@"this will be written to my_log"); 
// Now you can retrieve it back from the my_log as a proof of concept

您是在试图捕获来自您无法控制的代码的
NSLog
语句,还是在这里您可以用其他语句替换
NSLog
语句?我正在尝试捕获语句。嗯,我不确定应该怎么做,但我认为一个起点可能是检查
stdout
文件。我认为NSLog正在写它,就像printf一样。我不知道的是
stdout
是否以及何时自动刷新。
NSLog
实际上写入
stderr
。这对我不起作用。我知道我正在将数据传递给NSLog,并且我知道它不是空的。我想尝试从日志中检索它,作为概念证明。