At the moment I have one .nib file (it’s actually a .xib) containing ~15 windows/panels… All these windows get loaded on startup time and I was thinking, can’t I optimize the startup speed of my app if I split the windows in separate .nib files ? And then loading them when needed ? This will also require less memory because the unused windows won’t get loaded. Apple says this is the best way to go.
I can load .nib files with this
load nib "myNib"
But wouldn’t a call method be better ? I’d like to load it as fast as possible.
There’s this :
But I have no idea on how to get that working… I don’t even know I need that.
Also, when using such a call method, do I only need to execute it once so it doesn’t load the nib every time or does it take care of that itself ?
Any help would be very helpful. Thanks in advance.
Yes, you should use multiple nibs and only load the ones at startup that are needed for the reasons you stated. The thing to guard against when loading nib files is that you don’t load them more than once. When you load one its contents go into memory, so you don’t want that to happen multiple times. Therefore you need a variable to keep track of whether the nib is loaded. Try something like this…
property myNibWindow : missing value
Then in your code you would use it like this whenever you need to use that window. I don’t think using a call method here would make any difference in speed. The same process of loading happens whether you use the applescript command or the obj-c command to load the nib.
if myNibWindow is missing value then
load nib "nib name"
set myNibWindow to window "theWindowName" -- the name of the window in the nib
Ah thanks, I thought there would be a little optimization when using call methods…