Count the number of times a method is called in Cocoa-Touch?


Count the number of times a method is called in Cocoa-Touch?



I have a small app that uses cocos2d to run through four "levels" of a game in which each level is exactly the same thing. After the fourth level is run, I want to display an end game scene. The only way I have been able to handle this is by making four methods, one for each level. Gross.

I have run into this situation several times using both cocos2d and only the basic Cocoa framework. So is it possible for me to count how many times a method is called?


Inability to delete table cells after a certain point

1:

Is there an Cocoa or Objective C api for Java?
Can you just increment an instance variable integer every time your method is called?. Protocols with optional properties? I couldn't format the code in a comment, so to expound more:. How to determine where this memory leak is coming from? In your header file, add an integer as a instance variable: . Turn a page like a Book with UIView?
@interface MyObject : NSObject {     UIInteger myCounter;  } 
And then in your method, increment it: . Does anyone have the UIViewAdditions file from WWDC 2009 session 128? [closed]
@implementation MyObject     - (void)myMethod {        myCounter++;        //Do another method stuff here        if (myCounter>3){            [self showEndGameScene];        }       }  @end 
Is there access to the iPhone accelerometer using Javascript?only character - not special/numbers from keyboard - iPhone

2:

I don't know if your way is the best way to did it, or if mine is, although like Nathaniel said, you would simply define an integer to hold the count in your @interface:.
@interface MyClass : NSObject {     int callCount; } 
Then the method must increment this by doing:.
- (void) theLevelMethod {    callCount++;    // any  code } 
Make sure you initialize the callCount variable to 0 though, in your constructor or the equivalent of viewDidLoad. Then in the code this checks the count you must check:.
if (callCount == 4) {    // did  any thing, I guess end scene } 
Then again, I guess you must simply did any thing like this:.
for (int i = 0; i < 4; i++) {    [self theLevelMethod]; }  [self theEndScene]; 
I don't know how your game logic works, although I guess this would work.. Sorry if I misunderstood your question..


54 out of 100 based on 49 user ratings 1124 reviews