TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2017 |
Maintained by Joshua Greene.
BetterBaseClasses
are abstract, base classes meant to be subclassed.
Most view controllers will only have ONE nib or storyboard scene associated with them. BetterBaseClasses
lets you specify the identifier
, bundle
, and storyboardName
as part of the class- where it makes more sense for it to be in most cases.
This also makes creating and consuming a CocoaPod much easier.
In example, instead of having to call initWithNibName: bundle:
, which requires that the consuming app have knowledge of the nib name and the bundle, you can simply call the class method instanceFromNib
.
BetterBaseClasses
also provides convenience methods for working with views, too.
The easiest way to add BetterBaseClasses
to your project is using CocoaPods.
Simply add the following line to your Podfile:
pod 'BetterBaseClasses', '~> 1.0'
Then run pod install
as you normally would.
Follow these steps for manual installation:
Clone this repo locally onto your computer, or press Download ZIP
to download the latest master commit.
Drag the BetterBaseClasses
folder into your project.
Delete the BetterBaseClasses.h
file (it's a public header for when this included as a library/CocoaPod).
Instead of subclassing UIViewController
or UITableViewController
, you should subclass BaseViewController
or BaseTableViewController
, respectively.
(Optional) override commonInit
, which is called by all designated initializers, to run common setup code.
(Optional) override the class methods bundle
, identifier
, or storyboardName
. This allows you to specify the nib name or storyboard identifier right in the view controller.
In most cases, however, you won't need to override these as reasonable default values are already provided (e.g. nib name is expected to match the view controller's name, etc).
instanceFromNib
to instantiate a view controller from its nib or instanceFromStoryboard
to instantiate a view controller from its storyboard scene.For example,
------ TestViewController.h ------
#import "BaseViewController.h"
@interface TestViewController : BaseViewController
@property (assign, nonatomic) NSUInteger exampleValue;
@end
------ TestViewController.m ------
#import "TestViewController.h"
@implementation TestViewController
- (void)commonInit {
[super commonInit];
_exampleValue = 42;
}
@end
You could then instantiate a new TestViewController
from a nib named TestViewController.xib
like this:
TestViewController *viewController = [TestViewController instanceFromNib];
Win. :]
There are also convenience methods for working with views, too. See BaseView
and BaseTableView
for in-line documentation for more details.
BetterBaseClasses
is available under the MIT license (see the LICENSE file for more details).