1

According to a comment in UIViewController regarding initWithNibName:bundle:

If you invoke this method with a nil nib name, then this class' -loadView method will attempt to load a NIB whose name is the same as your view controller's class.

I always name my nibs the same as the view controller.

Is it a bad practice (i.e. unsafe, slower, or likely to cause problems down the road) to just pass nil to both parameters instead of a nib name string?

The main driving desire behind wanting to do this is I've found that using the refactor option in Xcode doesn't rename the nib name strings (only the class names wherever they're used). Thereby, this causes crashes if one isn't careful to go back and rename these everywhere.

JRG-Developer
  • 12,454
  • 8
  • 55
  • 81

1 Answers1

7

It's not unsafe or slow. It just means that there will be an extra check to see that the NIB with the same name as your class really exists in the bundle, then it will be loaded exactly as if you had passed the NIB name. It won't cause problems unless you decide to change how you name your NIBs. In face, there's a whole discussion about how -initWithNibName:bundle: is a bad initializer, and just using -init is better.

nevan king
  • 112,709
  • 45
  • 203
  • 241