如何使用NSLog
在日志中打印int*
(int指针)和unsigned int*
?
- (int) doSomethingWith:(unsigned int)Msg withWparam:(unsigned int*)wParam withParameter:(int *) lParam
{
NSLog(@"MSg:%d wParam:%u lParam:%u",Msg,wParam,lParam);
//not working
return 1;
}
警告: Format specifies type 'unsigned int' but the argument has type 'unsigned int *'
用%d
代替int
。形参是指针,所以使用*
来访问所指向的值。
NSLog(@"MSg:%d wParam:%u lParam:%d",Msg,*wParam,*lParam);
%@
用于对象。BOOL
不是对象。你应该使用%d
。
基于数据类型,%@
更改如下
For Strings you use %@
For int you use %i
For float you use %f
For double you use %lf