I have created a plugin and have some 3 classes called PluginPrincipalClass,ClassOne and ClassTwo.I have the following code snippet in my classes.
#import <Cocoa/Cocoa.h>
@interface PluginPrincipalClass : NSObject
@end
#import "PluginPrincipalClass.h"
@implementation PluginPrincipalClass
- (NSInteger)getDownloadPercentage
{
NSLog(@"getDownloadPercentage");
return 10;
}
- (void)downloadSoftwareUpdate
{
NSLog(@"downloadSoftwareUpdate");
}
@end
#import <Cocoa/Cocoa.h>
@interface ClassOne : NSObject
@end
#import "ClassOneh"
@implementation ClassOne
- (void)ClassOneMethod
{
NSLog(@"ClassOneMethod");
}
@end
#import <Cocoa/Cocoa.h>
@interface ClassTwo : NSObject
@end
#import "ClassTwo.h"
@implementation ClassTwo
- (void)ClassTwoMethod
{
NSLog(@"ClassTwoMethod");
}
@end
And in my BaseApplication to load the plugin and to call the principal classes I have the following code snippet
NSString *zStrPlugInsPath = [[NSBundle mainBundle] builtInPlugInsPath];
NSArray *zAryBundlePaths = [NSBundle pathsForResourcesOfType:@"plugin"
inDirectory:zStrPlugInsPath];
NSString * zStrPathToPlugin = [zAryBundlePaths lastObject];
NSBundle *znsBundlePlugin = [NSBundle bundleWithPath:zStrPathToPlugin];
// instantiate the principal class and call the method
Class zPrincipalClass = [znsBundlePlugin principalClass];
id zPrincipalClassObj = [[zPrincipalClass alloc]init];
NSInteger downloadPer = [zPrincipalClassObj getDownloadPercentage];
NSLog(@"downloadPer = %ld",downloadPer);
[zPrincipalClassObj downloadSoftwareUpdate];
This is working fine.If I want to call the method of ClassOne or ClassTwo.How to instantiate and call those methods from my base application.Is it similar to create the object ClassOne and call the methods with that object?
I (if I understand your question correctly), you want to use NSBundle’s
classNamed:method 🙂Like so: