Is there a way to use setValue:forKey which will take C-type variables?

iphone, objective-c

Solution

Similarly, `setValue:forKey:` determines the data type required by the appropriate accessor or instance variable for the specified key. If the data type is not an object, then the value is extracted from the passed object using the appropriate -Value method.

You can pass an `NSNumber`, and it will be automatically converted back into a float for your setter.

@interface MyClass ()

@property (nonatomic, assign) CGFloat example;

@end

@implementation MyClass

- (void)testSetter {
    [self setValue:@(5.0f) forKey:@"example"];
}

@end

Problem

I have some properties set up on an object, mostly `GLfloat` and I was wondering if there was a way to use `[self setValue:(id)value forKey:(id)key];` that would take a c style variable? It doesn't have to be `setValue:forKey` if there is an alternative if there is one available. My reasoning is I have a lot of properties on an object that are `floats` and I can pass an `NSDictionary` with values (`NSNumber` here is no issue) to set each relevant value. Ideally I could do this without enumerators or custom setters - is this doable?

Original source