iosobjective-coopobjective-c-category

Category is implementing a method which also be implemented in primary class : `viewWillAppear:`


I'm trying to category UIViewController to override viewWillAppear:. But getting this warning.

Category is implementing a method which also be implemented in primary class

@implementation UIViewController (ViewWillAppearCategory)

-(void)viewWillAppear:(BOOL)animated
{
    //.........
}

@end

I want to do some stuff during view appear in all screen, So I don't want to touch in all screen. that's why, go with category.

I may implement some method in sub class and I can call that method in all VC(all Screen). But I don't want this. It automatically invoke in view will appear call. Is this any idea to do this or did any mistake in above?

Note: This code will only appear in development phase for some testing purpose. So I'll remove this code when go with app store. So It should be easier task during removal, that is I won't touch all screen. I won't keep this code during submission to app store.


Solution

  • In such cases you must try Method Swizzling, a very nice formed concept which allows you to change the implementation of an existing selector.

    For more details and code please visit the link below.

    http://nshipster.com/method-swizzling/