Summary
Nibs / .xib files and storyboards are Builder interface files that are used to visually create a user interface for iOS and Mac applications in Xcode (I will use iOS terminology for classes, as this question is marked by iOS, but this also applies to Macs) .
Differences
Tips are intended for use with one UIView . They can also be connected to a subclass of UIViewController by setting the File Owner class to any subclass of UIViewController and attaching the output image (drag and drop to connect using the Connection Inspector in the right right pane of Xcode).
Frames must contain a user interface for 1 or more UIViewController . You can create an entire user interface in one storyboard or split it into smaller parts.
Benefits
Frames should always be used in favor of .xib / Nibs files (for view controllers). Cracking has more features and is being actively developed by Apple.
Every argument in favor of Nibs relies on being used individually, while storyboards contain many scenes. You can use one storyboard for each UIViewController as easily as you can with Nib (see Code Examples below). Keep reading for detailed explanations and code examples.
Detailed
Why do Storboards outperform Nibs?
The answer basically comes down to the fact that Apple encourages the use of storyboards and puts more effort into them.
- Storyboards have scaling capabilities that Nibs do not have. Seriously, you can't scale everything in Nibs, which sucks when designing for large screens on a small laptop.
- Nibs lacks key features, such as:
- Prototype and dynamic cells for
UITableView ( more ) - Property top layout guide (see comment)
- There are probably more, please edit or comment if you have anything to add to this list.
- You do not need to mess with setting up the Owner Owner class.
The main argument against storyboard is that having all of your view controllers in one place leads to merge conflicts, slow Xcode, slow build time, and general pain in the butt for support. Therefore, a general tip is to use Nib for each UIViewController .
But ... you can just create a storyboard for each UIViewController . A common practice (at least for me) is to hide all UIViewController initialization in the class method (since no other class should know the name of the file in which the Nib / Storyboard is located). Let's compare the related code snippets that you can use to create such a method. The only line of code is the whole difference between the two.
Objective-c
Storyboard
+ (ViewController *)create { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"ViewController" bundle:nil]; return [storyboard instantiateInitialViewController]; }
Nib
+ (ViewController *)create { return [super initWithNibName:@"ViewController" bundle:nil]; }
Using
- (void)showMyViewController { ViewController *vc = [ViewController create]; [self presentViewController:vc animated:YES completion:nil]; }
Swift
Storyboard
static func create() -> ViewController { let storyboard = UIStoryboard(name: "ViewController", bundle: NSBundle.mainBundle()) return storyboard.instantiateInitialViewController() as! ViewController }
Nib
static func create() -> ViewController { return ViewController(nibName: "ViewController", bundle: nil) }
Using
func showMyViewController() { let vc = ViewController.create() self.presentViewController(vc, animated: true, completion: nil) }
Arguments
I will consider all the usual arguments for Nibs; as I mentioned earlier, mostly single files are used, not as an argument for Nibs over Storyboards
Argument: having a storyboard with a lot of controllers cause merge conflicts if you work in a team with several people making changes
Answer. A single storyboard does not cause more merge conflicts than a single Nib
- Complexity
Argument: very sophisticated applications have many scenes in the storyboard, which leads to a giant storyboard that loads forever and is hardly understandable because of its size.
Answer: This is a great moment, but you can easily break the Chipping into smaller parts. Storyboard links look like a great feature that can be used to connect Storyboards together, but they are only available in Xcode 7 / iOS 9+. In addition, there is still no reason to select individual Nibs over Storyboards.
- Reuse
Argument: creating a Nib for each subclass of the UIViewController allows you to reuse the code, so you donโt need to configure all your restrictions and access points for each scene in your storyboard.
Response: Again, no reason to choose individual Nibs for individual storyboards.