Paul
Paul

Reputation: 6176

why bundle is nil, after initWithNibName? objective-c

i was wondering : why do we set "bundle" to "nil", when we alloc-init a viewController?

example :

MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

Thanks

Paul

Upvotes: 2

Views: 5447

Answers (3)

Yuji
Yuji

Reputation: 34185

Using nil there is equivalent to using [NSBundle mainBundle]. Read the documentation.

In general, if you have any question about a method in an Apple-provided class, first read the official documentation before coming here :)

Upvotes: 2

ms83
ms83

Reputation: 1814

As it is says in the documentation:

Parameter - nibBundle

The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle.

Since your nib is in the main bundle you can just set that parameter to nil. If it was not you would have to tell it where to search.

Upvotes: 2

Evgeny Shurakov
Evgeny Shurakov

Reputation: 6082

If bundle is nil, this method looks for the nib file in the main bundle. So it's the same as to pass [NSBundle mainBundle]

See UIViewController class reference

Upvotes: 6

Related Questions