I am coding a fairly complex system that uses a lot of metadata to manage dynamic objects. I am using various objective-c runtime features. I want to add stuff to mutable dictionaries which are properties within various classes. I want to do this where I know the class type and I know the property name, but I don’t want to ‘hard code’ the assignment. If I hard-coded it I could do this:
[[(myknownclass*)localClassObjectInstance knownDictionary] setObject:value forKey:key];
but what I want to do is something like this:
[[unknownClassObjectInstance {aStringContainingTheDictionaryName}] setObject:value forKey:key];
How can I reference the mutable dictionary property when I only have the name of the property at runtime?
You can use
-valueForKey:to run the method:Or alternatively, you can use
performSelector: