Some questions about NSBundle and osx
Some questions about NSBundle and osx
- Subject: Some questions about NSBundle and osx
- From: Gore <email@hidden>
- Date: Fri, 23 Nov 2001 21:48:08 +0200
There are 3 questions I would be happy to get answer for:
1:
I have created an app that downloads a picture from a www-site and saves
it to the disk in the ~/Documents/ directory, it would be fun to have
macosx directly update and use that picture as desktop-picture, is that
possible ?
2:
I would like to know how to load bundles correctly, should I have a
NSBundle instance global or can I release the NSBundle instance I used
to load the classes with ?
3:
What should I do to load the resources inside a bundle in a correct
way ? here is what I do right now, this code is inside my NSDocument
class, used to load the interface for my plugins, but if I open a new
document and try to load it again, it gives me the "Error in loading
interface." error, hmm...please help, newID is a global instance.
- (IBAction)runPluginWithMenu:(id)sender // sender is a NSMenuItem
{
NSBundle *thePlugin = [NSBundle bundleWithPath:
[[[NSBundle mainBundle] builtInPlugInsPath]
stringByAppendingFormat: @"/%@.bundle", [sender title]]];
currentPluginName = [sender title];
if ( runningPlugin == NO ) // just to be safe...
{
if ( [thePlugin load] )
{
newID = [[[thePlugin principalClass] alloc] init];
[newID setCurrentDocument: self];
if ( [newID pluginIsGUI] )
{
if ( [NSBundle loadNibNamed: @"PluginInterface" owner:
newID] ) // should the owner be a class or instance!?
{
[pluginsPanel setMinSize: newFrame.size];
[pluginBox setContentView: [newID pluginView]];
runningPlugin = YES;
[NSApp beginSheet: pluginsPanel modalForWindow:
docWindow
modalDelegate: self didEndSelector: NULL
contextInfo: nil];
}
else
NSRunAlertPanel( [sender title], @"Error in loading
interface.", @"OK", nil, nil );
}
else
{
runningPlugin = YES;
[self runThePlugin: self];
}
}
else
NSRunAlertPanel( [sender title], @"Error in loading
plugin.", @"OK", nil, nil );
}
}