Main class NSBundle

Plz help me understand what mainClass is used for? What is its syntax. I understand that this is in the NSBundle class, but can we create it for any packages, is it specific only for paladised packages? Plz help me learn the concept of mainClass.

Thank you.

+5
source share
3 answers

I will give you an example of how you can create and download a package as a plugin. Hope this helps you a lot. I have to say that I agree with the other 2 (for now) answers. So that...

Create an Xcode project as a "Bundle" (in Xcode 3.2.6, in New Project-> Framework and Library-> select "Bundle"). Create the following files ...

PClass.h

#import <Foundation/Foundation.h>
@interface PClass : NSObject {

}

- (NSString*) stringMessage;

@end

PClass.m

- (NSString*) stringMessage {
    return @"Hallo from plugin";
}

.plist :

" " "MyPlugin"

" " "PClass"

(.../build/Debug/yourPlugin.bundle) , ( aProject.app/Plugins/ ).

Xcode :

- (void) loadPlugin {

    id bundle = [NSBundle bundleWithPath:@"the path you/placed/yourPlugin.bundle"];

    NSLog(@"%@", [[bundle infoDictionary] valueForKey:@"CFBundleDisplayName"]);
    // Here you can preview your plugins names without loading them if you don't need to or just to
    // display it to GUI, etc

    NSError *err;
    if(![bundle loadAndReturnError:&err]) {
        // err 
    } else {
        // bundle loaded
        Class PluginClass = [bundle principalClass]; // here is where you need your principal class!
        // OR...
        //Class someClass = [bundle classNamed:@"KillerAppController"];

        id instance = [[PluginClass alloc] init];

        NSLog(@"%@", [instance stringMessage]);

        [instance release];  // If required
    [bundle unload]; // If required
}

}

.

+6

" " - Objective-C, , , -principalClass .

, .

, Objective-C.

+4

, , . , , . Objective-C runtime "CSISharpener.bundle", . , , .

mainClass CSISharpeningFilter, , . , "mainClass" , , .

In other words, mainClass allows programs that download packages and an easy way to find the “entry point” to the code you just downloaded. Exactly what it is used for will depend on what code loads the package and what it uses it for.

+3
source

All Articles