Re: Accessing project images in IB Plugin
Re: Accessing project images in IB Plugin
- Subject: Re: Accessing project images in IB Plugin
- From: Jon Hess <email@hidden>
- Date: Mon, 5 Nov 2007 11:30:07 -0800
On Nov 3, 2007, at 7:06 PM, Ricky Sharp wrote:
On Nov 3, 2007, at 8:16 PM, Rainer Brockerhoff wrote:
At 15:22 -0700 03/11/2007, email@hidden wrote:
From: Ricky Sharp <email@hidden>
Date: Sat, 3 Nov 2007 16:41:07 -0500
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
I'm having a bit of difficulty having my IB Plugin custom classes
access images in the opened Xcode project.
When building my IB 2.x palettes, I had to write custom palette
loading code to scan all the project images and load them in memory.
This allowed me to have an NSString* ivar for say a custom view.
In the view's drawRect:, I just needed to do:
NSImage* theImageToDraw = [NSImage imageNamed:[self myImageName]];
....
* The only solution I came up with to use my existing drawing
code, and see the image at both design-time and in the simulator,
is to add the images to the framework as part of the IB plugin.
It works great, but that's going to be a maintenance nightmare.
Right, this is what I do; the images are in my plugin's resources
folder.
NSImage* theImageToDraw = [[NSImage alloc] initWithContentsOfFile:
[[NSBundle bundleForClass:[self class]] pathForImageResource:[self
myImageName]]];
and I do that only once, in the IBPlugin's didLoad method. (Release
them in the willUnload method.)
Rainer,
Glad to see at least one other person is came up with the same
solution :)
Anyhow, I do use an "image factory" for all image loading (the
plugin as well as my apps define the same API). All images are only
loaded once and then just cached.
I may look into tapping into 'didLoad'. One thing I read though in
the docs is that willUnload is not guaranteed to be called? Thus,
it may be better to do your releases in the plugin's dealloc or
finalize methods instead.
Right, willUnload is only called when the user manually unloads your
plug-in from the preferences panel.
Also, to cut down on maintenance, I added another target to my
application which builds an 'image framework'. The app already had
a folder of images, so was easy to just include that in the
framework's resources folder. I also created a dummy class (just an
empty subclass of NSObject) as the framework's principal class.
In my plugin project, I then added the framework as a linked
framework to the plugin's framework. This will allow me to add/
remove images to the 'image framework' without having to always
recompile the plugin.
Thankfully, my plugins are also only for in-house use. Eventually,
when I start authoring my second application, I'll have to add in
that app's 'image framework' into the plugin as well.
So while this all feels not really elegant, it does give me images
for both design-time and simulator.
I think I'm going to file an enhancement request. Perhaps there's
something Apple can do to make Xcode resources visible to the
simulator?
I think filing that bug would be a great idea.
Jon Hess
_______________________________________________
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