Given an object, and a method within, is there some way to get the name of 
the class of the object as an NSString?
  For that matter, what I want to do is something like this:

Class MyClass
"MyClass.h"
#import <Foundation/Foundation.h>

@interface MyClass : NSObject

...

-(void)myMethod;

@end

"MyClass.m"
#import "MyClass.h"

@implementation MyClass

...
-(void)myMethod
{
NSString *myClassName = ???; // What can I put here besides a literal 
@"MyClass"?

NSString *fooText = [NSString stringWithFormat:@"<%@> -(void)myMethod", 
myClassName];
NSLog(fooText); // Yellow triangle on this line
}
...
@end

so that when the myMethod message is sent to an object of MyClass, the output 
should be:

<<timestamp>>: <MyClass> -(void)myMethod

on the output pane when debugging - "<<timestamp>>" just comes from the NSLog 
call.

  Also, when I do this (using a literal NSString constant for myClassName 
above), Xcode marks the line with NSLog with a yellow triangle, and disclosing 
it says something about passing an NSString instance as being "unsecure". Can 
this warning be turned off? It seems silly to do:

NSLog(@"%@", fooText);

just to avoid this warning.
  By using this strategy, if several classes implement the same message, I can 
tell which instance received the message during debugging; this is handy when 
iterating over containers (such as NSArray), and passing the same message to 
multiple objects, or when passing messages to objects of subclasses that 
override the behavior of their super.
  TIA!



_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to