任何方式要求一个方法的名称? [英] Any way to ask a method for its name?

查看:145
本文介绍了任何方式要求一个方法的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试我正在开发的iPhone应用程序,并且向各种源文件添加五十个NSLog语句的想法给了我一切。

I'm trying to debug an iPhone app I'm working on, and the idea of adding fifty NSLog statements to the various source files gives me the willies.

我想要做的是写一对语句,如

What I'd like to do is write a pair of statements, say

NSString *methodName = [self methodName];
NSLog(@"%@", methodName);

,我可以粘贴到我需要的每个方法。有办法做到这一点吗?是否有一些Objective-C构造,要求一个方法的名称?

that I can just paste into each method I need to. Is there a way to do this? Is there some Objective-C construct for asking a method for its name? Or am I gonna have to do this the hard way?

推荐答案

尝试 NSLog(@%s ,__func __)。这打印出一个漂亮的描述,如 - [MyView drawRect:]

Try NSLog(@"%s", __func__). This prints out a pretty description, like -[MyView drawRect:].

这也适用于函数。这是一个编译器功能。

This also works with functions. It's a compiler feature.

这篇关于任何方式要求一个方法的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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