プラグインを作成し、PluginPrincipalClass、ClassOne、ClassTwoという3つのクラスがあります。クラスには、次のコードスニペットがあります。
#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
そして、プラグインをロードしてプリンシパルクラスを呼び出すためのBaseApplicationには、次のコードスニペットがあります。
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];
これは正常に機能しています。ClassOneまたはClassTwoのメソッドを呼び出したい場合。ベースアプリケーションからこれらのメソッドをインスタンス化して呼び出す方法。オブジェクトClassOneを作成し、そのオブジェクトでメソッドを呼び出すのと似ていますか?