Objective C best way to see how many times a method is called
Asked Answered
L

2

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

Lais answered 11/10, 2011 at 12:55 Comment(2)
You tried good ol' NSLog where you fire the method?Oatmeal
Its in far too many places, and the method is in Cocoa libraries. I want an easyish way to do it. But there will be an NSLog involved at some point.Lais
C
1
-(void) method {

   static int callCount = 0;
   callCount++;

   /* method body */

}
Charlsiecharlton answered 11/10, 2011 at 13:6 Comment(2)
The method i want to track is in Cocoa library - but what you have written it what I would use normally. ThanksLais
@Lais perhaps you could get some kind of answer out of instruments?Charlsiecharlton
I
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.

Inhale answered 11/10, 2011 at 13:8 Comment(4)
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?Lais
Did you try this method? #1638104Inhale
You shouldn't use method swizzling tho. #5339776Oatmeal
Yeah, this is solely for debugging and performance improvements. I'm not putting this code into production with method swizzles.Lais

© 2022 - 2024 — McMap. All rights reserved.