Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7090493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:41+00:00 2026-05-28T08:03:41+00:00

I am aware of NSStringFromClass. My question relates to the situation where the same

  • 0

I am aware of NSStringFromClass.

My question relates to the situation where the same method is implemented in multiple classes in an inheritance tree, and you want to debugging information as to which class it is executing from.

Example:

Let us have three classes: A–>B–>C , inheriting as displayed by the arrows.

If each of them has a method foo(), defined:

-(void) foo
{
 // Do some work particular to the class it is in.
  .....
  //Each method ends with the debugging statement:
  NSLog("In foo of class:%$",NSClassFromString([self class]));
}

The problem occurs when foo of Class B, calls [super foo]. When [super foo] (i.e. Class A) reaches the NSLog statement, [self class] returns class B, and not A.

Likewise if C called [super foo], the log statement in super would log class C.

What I want to do, is output the class whose method implementation is being executed – so if class B calls [super foo], then the log statement in [A foo] outputs Class A.

The simple way is to replace NSClassFromString with a hardcoded string representing the class name, but I was wondering if there is a better way to do this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:03:42+00:00Added an answer on May 28, 2026 at 8:03 am

    You can use __PRETTY_FUNCTION__ to include both the class and the method name:

    NSLog(@"Greetings from %s", __PRETTY_FUNCTION__);
    

    I don’t believe that there is a compiler-time macro for just the class name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I aware that this will be a less programming question, but still... How can
I'm aware it's a quite simple question but I'm a newbie to C#, ASP.NET
I'm aware of jQuery's append() which appends html inside the selected element. I want
I am aware of sending form values using the method=get <FORM METHOD=get ACTION=test.html> I
You must be aware of the .NET method DateTime.FromOADate(double d). I need to implement
I am aware of this question , but it does not appear to work
Im aware this may be a slightly odd question, but given a Page class
Anyone aware of a method/class/library that will allow me to easily reproduce the results
I'm aware of the .delay() method, but I believe that only applies to adding
Anyone aware of guidance on creating a custom SSIS connection manager? I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.