1

I want to determine how many times a particular method is called on NSManagedObject.

What are anybody's suggestions for the best way of doing this?

Bearing in mind that i have 30+ managed objects and I don't want to change the superclass of all of them.

Thanks

bandejapaisa
  • 26,576
  • 13
  • 94
  • 112

2 Answers2

1
-(void) method {

   static int callCount = 0;
   callCount++;

   /* method body */

}
jbat100
  • 16,757
  • 4
  • 45
  • 70
1

Create an alternate method in a category that tracks the number of calls in a static variable and the swizzle the method with the original implementation. See http://www.cocoadev.com/index.pl?MethodSwizzling for a code sample.

Jano
  • 62,815
  • 21
  • 164
  • 192
  • This swizzle code doesn't want to compile with Xcode 4.2 on LLVM 3 against iOS 5..... this was the way I thought of doing it originally, but thought there might be another way that I've forgotten about... any other suggestions? – bandejapaisa Oct 11 '11 at 13:45
  • Did you try this method? http://stackoverflow.com/questions/1637604/method-swizzle-on-iphone-device/1638940#1638940 – Jano Oct 11 '11 at 14:10
  • You shouldn't use method swizzling tho. http://stackoverflow.com/questions/5339276/what-are-the-dangers-of-method-swizzling-in-objective-c – Totumus Maximus Oct 11 '11 at 14:56
  • Yeah, this is solely for debugging and performance improvements. I'm not putting this code into production with method swizzles. – bandejapaisa Oct 11 '11 at 16:02