And the code in that article still holds true. As you know, reflection is really expensive but sometimes a necessary evil. However, it's especially expensive for value types because of boxing and unboxing.

Basically, whenever you use reflection, Obj-c takes the value and wraps it in an NSValue object or an NSNumber if you're dealing with a number.

Today, I'm going to show you, how you can actually skip the boxing and unboxing. Although it's a bit tricky, it'll definitely speed up your application if you're using reflection to loop through large amounts of data.

To keep the topic as simple as possible, I'm going to show you how to do this for double's. However, you can customize this to support any other value type, although you'll have to know what value types you're supporting up front.

First we need to typedef a method called "getDouble" that will return our value:

typedef double (*getDouble)(id, SEL);

Next we need to define a block called "helperBlock" that we will invoke for reflection: