Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C find caller of method

Is there a way to determine the line of code a certain method was called from?

like image 500
ennuikiller Avatar asked Sep 20 '09 15:09

ennuikiller


1 Answers

StackI hope that this helps:

NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1]; // Example: 1   UIKit                               0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"]; NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString  componentsSeparatedByCharactersInSet:separatorSet]]; [array removeObject:@""];  NSLog(@"Stack = %@", [array objectAtIndex:0]); NSLog(@"Framework = %@", [array objectAtIndex:1]); NSLog(@"Memory address = %@", [array objectAtIndex:2]); NSLog(@"Class caller = %@", [array objectAtIndex:3]); NSLog(@"Function caller = %@", [array objectAtIndex:4]); 
like image 97
intropedro Avatar answered Oct 19 '22 02:10

intropedro