I have an object which straight forward instance variables. Some are NSString, some are unsigned ints, etc. I was under the impression Key-Value coding was scriptable in that I could write code such as the following:
id key, value;
key = [[attributes objectAtIndex:j] name];
value = [[attributes objectAtIndex:j] stringValue];
[obj setValue:value forKey:key];
The reason I'm using stringValue here and name is I'm working with TouchXML and building objects from XML feeds.
The code above crashes if I try to assign anything to an integer. If I change my unsigned int to an instance of NSString, there isn't any run-time crashes. It was to my understanding that Key-Value coding is smart enough to detect these issue.
What are my possible solutions? How can I abstract this as much as possible so I can run the same method on many different classes which all have their own instance variables?
Is the most elegant method to really override my setter and use NSNumber to convert the string into a type int, which I thought was already handled by KVC?