Nat! bio photo

Nat!

Senior Mull

Twitter Github Twitch

IMP cacheing and NSBundleDidLoadNotification

Here's something that I thought up on the toilet. The toilet is my primary - well actually sole - source of inspiration. It's like in an RPG.

You enter the magical shrine of serenity. 
Your intelligence went up by 20.
"Excellent!"
...
You leave the magical shrine of serentiy. 
Your intelligence went down by 20.
"Duh!"

With this intro, if you'd think the idea I am now to present is going to be really great, you could be mistaken.

Anyway...

In writing EOF classes I try to use a bit of IMP caching for some often used Objective-C calls. Even with the advent of fast Objective-C message calls in 10.4 this can be still a time saver. But a niggling problem is that in a dynamic system the IMP can get stale overtime. Stale IMPs can happen f.e. when a new category is loaded. I used to ignore this, but now I had this idea If instances listen for the NSBundleDidLoadNotification notification then they could recache the IMPs and things would be more robust.

But what I don't want is to register every object I fetch. Oh wait...