Let's say I have a code like this...
- (id) init {
...
self.myImage1 = [NSImage imageNamed:@"some_image_name"]; // setter retains
...
}
- (void) setStatusItemImage
{
[self.statusItem setImage:self.myImage1];
}
I also want to animate the status item so I created 6 variants of the "updating" status item icon and loop it over an NSTimer, with target method similar to the above. Questions are:
As the proverb goes, premature optimization is the root of all evil. Measure first, then optimize whatever's slow, then measure again to make sure it helped.
That said, imageNamed:
is slow. You almost always should use NSBundle and -[NSImage initWithContentsOfFile:]
instead.
is it OK if I use a retained / preloaded NSImage?
Why would you not? And why would the status item care whether the image is retained by something else or not?
Is there a way to animate the status item in a more efficient way?
setImage:
is the only way. As long as you're not loading each image every time, you should have no efficiency problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.