Even further you can get the current command by using NSStringFromSelector(_cmd); _cmd is the current selector.
You can also use NSLog(@“%s”, _PRETTY_FUNCTION”) which will give you the class name and current selector. Do a google search also for NSLog replacements there are ones that do a lot of work of prepending all NSlog calls with class, function, line number and you custom message. Like the answer here: http://stackoverflow.com/questions/969130/how-to-print-out-the-method-name-and-line-number-and-conditionally-disable-nslog Scott On Mar 6, 2014, at 10:21 AM, William Squires <wsqui...@satx.rr.com> wrote: > 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 (Cocoa-dev@lists.apple.com) > > 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/scottandrew%40roadrunner.com > > This email sent to scottand...@roadrunner.com
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com