如何在Cocoa / Objective C中通过NSLog记录当前行? [英] How can I log the current line via NSLog in Cocoa / Objective C?

查看:49
本文介绍了如何在Cocoa / Objective C中通过NSLog记录当前行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cocoa / Objective C中是否可以使用NSLog记录当前行号?

Is it possible to log the current line number using NSLog in Cocoa / Objective C?

我想我应该这样做:

NSLog(@"current line: %@ and value: %@",__LINE__,abc);

我得到线程1:程序接收到信号: EXC_BAD_ACCESS

推荐答案

__ LINE __ 宏提供了整数,因此您需要更改格式字符串。而不是%@ ,您需要一个%d

The __LINE__ macro provides an integer so you need to change your format string. Instead of %@ you need a %d.

NSLog(@"current line: %d",__LINE__);

这篇关于如何在Cocoa / Objective C中通过NSLog记录当前行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆