title: What is the best way to share methods across classes in Objective C?
body: <p>I have several view controllers and table view controllers that I push from my root view controller. In all of these I'd like to use a custom back button in the navigation controller. Instead of copying the method to set up my back button into each class, file, I've created a helper class with a class method that does the setup. The code below works, but I'm wondering if I'm going about this the wrong way. Is there a better way to achieve this? Also, I'm still duplicating the -(void)myCustomBack method in all my classes and was wondering if there's a way to avoid that as well.</p>
  
  <pre><code>@interface NavBarBackButtonSetterUpper : NSObject
  + (UIButton *)navbarSetup:(UIViewController *)callingViewController;
  @end
  
  @implementation NavBarBackButtonSetterUpper
  
  + (UIButton *)navbarSetup:(UIViewController *)callingViewController
  {
      callingViewController.navigationItem.hidesBackButton = YES;
  
      UIImage *backButtonImage = [[UIImage imageNamed:@"back_button_textured_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
  
      UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
  
      [backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
  
      [backButton setTitle:@"Back" forState:UIControlStateNormal];
      backButton.titleLabel.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:12];
      backButton.titleLabel.shadowOffset = CGSizeMake(0,-1);
  
      UIView *customBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
      [customBackView addSubview:backButton];
  
      callingViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customBackView];
  
      return backButton;
  }
  @end
  
  
  
  @interface MyCustomTableViewController : UITableViewController
  @end
  
  @implementation MyCustomTableViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      UIButton *backButton = [NavBarBackButtonSetterUpper navbarSetup:self];
  
      [backButton addTarget:self  action:@selector(myCustomBack) forControlEvents:UIControlEventTouchUpInside];
  }
  
  - (void)myCustomBack
  {
      [self.navigationController popViewControllerAnimated:YES];
  }
  @end
  
  
  @interface MyCustomViewController : UIViewController
  @end
  
  @implementation MyCustomViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      UIButton *backButton = [NavBarBackButtonSetterUpper navbarSetup:self];
  
      [backButton addTarget:self  action:@selector(myCustomBack) forControlEvents:UIControlEventTouchUpInside];
  }
  
  - (void)myCustomBack
  {
      [self.navigationController popViewControllerAnimated:YES];
  }
  @end
  </code></pre>