Ant*_*ake 13 c iphone objective-c ios
我在静态库中有一些C代码,我正在编译成一个iPhone应用程序.我想将一些调试消息打印到控制台; 是否有像我应该使用的NSLog?我猜测NSLog只适用于程序的Objective-C部分.
编辑:fprintf(stdout,fmt ...)和fprintf(stderr,fmt ...)也不起作用..任何想法为什么他们不这样做?他们应该工作吗?
Mic*_*ann 10
你可以随时做经典:
fprintf(stderr, "hi, this is a log line: %s", aStringVariable);
Run Code Online (Sandbox Code Playgroud)
如果您混合使用Objective-C代码,则可以为NSLog做一个包装:
void debug(const char *message, ...) __attribute__((format(printf, 1, 2)));
Run Code Online (Sandbox Code Playgroud)
#import <Foundation/Foundation.h>
#import "log.h"
void debug(const char *message,...)
{
va_list args;
va_start(args, message);
NSLog(@"%@",[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:message] arguments:args]);
va_end(args);
}
Run Code Online (Sandbox Code Playgroud)
然后,在您的C文件中:
#include "log.h"
...
debug("hello world! variable: %d", num);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7726 次 |
| 最近记录: |