0

Memory use and cpu time can be available like below.

Programmatically retrieve memory usage on iPhone

And also i'd like to know the number of views to check performance? Is it possible?

Community
  • 1
  • 1
bekkou68
  • 802
  • 1
  • 9
  • 20

2 Answers2

0

I solved myself. call countViewsInApp. thx.

+ (int)countViewsInApp {
    int num = 0;

    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        for (UIView *aView in [window subviews]) {
            num++; // parent
            num += [self countSubviews:aView];
        }
    }

    return num;
}

+ (int)countSubviews:(UIView *)view {
    int num = 0;

    for (UIView *subview in [view subviews]) {
        num++;
        if ([[subview subviews] count] > 0) {
            num += [self countSubviews:subview];
        }
    }

    return num;
}
bekkou68
  • 802
  • 1
  • 9
  • 20
0

You can do like that:

- (NSUInteger *)countSubviewsInViewСonsideringView:(UIView *)view {
   NSUInteger subviewsCount = 1; // the current view
   for (UIView *subView in view.subviews) {
      subviewsCount += [self countSubviewsInViewСonsideringView:subView]
   }
   return subviewsCount;
}

somewhere in code:

UIWindow* window = [[UIApplication sharedApplication] keyWindow];
NSUInteger count = [self countSubviewsInViewСonsideringView:window];
BergP
  • 3,453
  • 4
  • 33
  • 58