views:

213

answers:

2

hello,

Plz help me to understand what is principalClass used for?what is the syntax of it. i understand tat it is in NSBundle Class,but can we create it for any bundles of is it specific only for laodable bundles? plz help me to know the concept of principalClass.

Thanking You.

+2  A: 

The "principal class" of a bundle is merely the Objective-C class that is marked as the primary class of the bundle and, thusly, will be returned by the -principalClass method of the bundle instance.

Nothing more, nothing less and there is no magic.

It only exists for loadable bundles because only loadable bundles define new Objective-C classes.

bbum
Thanku.. can u give me links for any opensource project which has used principalClass in it.
suse
+1  A: 

The principalClass allows you to know what class to start using once you have loaded a bundle. For example, say you are using bundles to represent plugins for an image processing app. When you tell the Objective-C runtime to load the bundle "CSISharpener.bundle", it will load a bunch of new classes into memory. However, you still need to know the name of the class to send messages to in order to actually use the plugin.

In our example, principalClass might return CSISharpeningFilter, which is conforms to the plugin protocol we told the plugin developers to use. So we can create an instance of "principalClass" and start using it, without knowing ahead of time what the class name is.

In other words, principalClass is there to allow the programs that load bundles and easy way to find an "entry point" into the code they have just loaded. Exactly what it is used for is going to depend on what code is loading the bundle and what it is using it for.

benzado