Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name conventions for xibs

I've been looking at the sample code and sometimes Apple names xib files ClassNameView and sometimes ClassNameViewController. The ClassName is always a UIViewController or UITableViewController, which had me wonder what convention to use when naming a xib. I would think View as it's not really the ViewController, but curious on what the convention is or at least what your naming conventions are for xibs.

like image 702
baalexander Avatar asked Jun 06 '09 16:06

baalexander


2 Answers

CocoaTouch supports both conventions, with a preference for the shorter form ClassNameView, as per the nib loading process described below when a nib name is not specified (from the UIViewController documentation, under nibName):

Specifically, it looks (in order) for a nib file with one of the following names:

  1. If the view controller class name ends with the word “Controller”, as in MyViewController, it looks for a nib file whose name matches the class name without the word “Controller”, as in MyView.nib.

  2. It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is MyViewController, it looks for a MyViewController.nib file.

So as other have said, it's a matter of preference! I personally like the shorter version but can see the logic in both.

like image 98
Clafou Avatar answered Nov 08 '22 06:11

Clafou


I use ClassNameView since the xib represents the view, not the view controller. I don't think there is a generally accepted convention.

like image 20
henning77 Avatar answered Nov 08 '22 06:11

henning77