Re: objc looks for Tiger class which should be weak-linked
Re: objc looks for Tiger class which should be weak-linked
- Subject: Re: objc looks for Tiger class which should be weak-linked
- From: "Kyle Sluder" <email@hidden>
- Date: Thu, 23 Aug 2007 13:57:23 -0400
Remember that -[init] is not always the designated initializer, so
don't use that method for loading arbitrary plugins. It's always a
good idea to define a formal protocol and test that the class you're
loading conforms to it.
--Kyle Sluder
On 8/23/07, Jerry Krinock <email@hidden> wrote:
> On 2007 Aug, 22, at 7:42, Kyle Sluder wrote:
>
> > I'm not sure how far you'll get by using a framework rather than a
> > bundle. I was thinking it would be easier to load a bundle at
> > runtime. Frameworks, as far as I know, are loaded by the dynamic
> > linker when you run the program and so I think you're going to end
> > up with the same problem that you originally had.
>
> Yes, I was taking things one step at a time here. Actually, I
> thought I was going to put a framework in a bundle, but after playing
> with Xcode some I learned that a bare "Cocoa Bundle" project will
> actually ^compile^ code. I still had to do all the refactoring, so
> not much work was wasted.
>
> Anyhow, Kyle, your remarks above are correct, and it works, and it's
> done, and I thank you very much for helping me, since I never would
> have figured this out from reading Apple's "Cross-Development
> Programming Guide". The "Bundle Programming Guide" explains how to
> load code from bundles, but doesn't mention that cross-development
> when an ^entire^class^ is missing from the previous OS is a very good
> reason why one would want to do such a silly thing. (I've submitted
> a documentation bug, suggesting that they tie this together.)
>
> Creating the Cocoa Bundle doesn't seem to be documented very much
> either, but fortunately it seems to "just work" similar to other
> project types.
>
> Here's a little function I wrote to create an instance of a class
> defined in a bundle:
>
> + (id)allocInitInstanceOfClassNamed:(NSString*)className
> inBundleNamed:(NSString*)bundleName {
>
> NSString* bundlePath = [[NSBundle mainBundle]
> pathForResource:bundleName
>
> ofType:@"bundle"] ;
> id instance = nil ;
> if (bundlePath) {
> Class class ;
> NSBundle* bundle = [NSBundle bundleWithPath:bundlePath] ;
> if (bundle) {
> if ((class = [bundle classNamed:className])) {
> instance = [[class alloc] init] ;
> }
> else {
> NSLog(@"Could not load class %@ from bundle %@",
> className, bundleName) ;
> }
> }
> else {
> NSLog(@"Could not load bundle at %@", bundlePath) ;
> }
> }
> else {
> NSLog(@"Could not get path for bundle %@", bundleName) ;
> }
>
> return instance ;
> }
>
>
>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden