Skip to content
Browse files

Print name of class and method.

  • Loading branch information...
1 parent c6fbb61 commit 84155f8773fe5b7b4d08adba8f673e44a59d6f83 @mudphone committed Mar 27, 2012
View
4 ObjcPlayground/ObjcPlayground/PDCViewController.h
@@ -10,4 +10,8 @@
@interface PDCViewController : UIViewController
+- (void)playInUhPlayground;
+- (NSString *)nameOfClass:(Class)class;
+- (void)printMethodsOfClass:(Class)class;
+
@end
View
28 ObjcPlayground/ObjcPlayground/PDCViewController.m
@@ -7,6 +7,7 @@
//
#import "PDCViewController.h"
+#import <objc/objc-runtime.h>
@interface PDCViewController ()
@@ -18,6 +19,7 @@ - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
+ [self playInUhPlayground];
}
- (void)viewDidUnload
@@ -31,4 +33,30 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
+#pragma mark - Playground (a bit hokey)
+
+- (void)playInUhPlayground
+{
+ if (YES) NSLog(@"Name of class is: %@", [self nameOfClass:[NSObject class]]);
+ if (YES) [self printMethodsOfClass:[NSString class]];
+}
+
+- (NSString *)nameOfClass:(Class)class
+{
+ return [NSString stringWithUTF8String:class_getName(class)];
+
+}
+
+- (void)printMethodsOfClass:(Class)class
+{
+ unsigned int count = 0;
+ Method *methods = class_copyMethodList(class, &count);
+ for (unsigned int i = 0; i < count; i++) {
+ SEL sel = method_getName(methods[i]);
+ const char *name = sel_getName(sel);
+ NSLog(@"%@ method: %@", [self nameOfClass:class], [NSString stringWithUTF8String:name]);
+ }
+ free(methods);
+}
+
@end

0 comments on commit 84155f8

Please sign in to comment.
Something went wrong with that request. Please try again.