So instead I have chosen to just integrate the code into that Objective-C code base. So load the code:
NSData *classdefSchemeCode=[self frameworkResource:@"classdef-method-browser-scheme" category:@"stsh"];
[interpreter evaluateScriptString:[classdefSchemeCode stringValue]];
Then instantiate the class after finding it reflectively via
NSClassFromString()
-(void)awakeFromNib
{
...
self.methodStore = [NSClassFromString(@"ClassBrowser") store];
}
So far, so easy. Of course, the big problem with bridged code usually comes now: the compiler doesn't know about code loaded at runtime, so you need to somehow duplicate the class's interface and somehow convince the compiler that the newly loaded class conforms to that interface.
But wait! This is a scheme-handler, which is a store, meaning it doesn't really have any unique interface of its
own, but rather just implements the MPWStorage
protocol. So all I have to do is the following:
@property (nonatomic, strong) id methodStore;
And I'm good to go!
This is unexpected in two ways: first, the integration pain I was expecting just didn't appear. Happy. Second, and maybe more importantly, the benefit of uniform interfaces, which I thought should appear, actually did appear!
So very happy.
No comments:
Post a Comment