Casting a string as an instance variable.
I would like to do something like: MyObject updateWIth: aDictionary. then, inside the object, treat the keys as instance variables, and the values as values.. and do something like: (key1 asInstanceVariable(??)): value1. this seems like it should be possible, but i am just not getting it. any ideas? thanks!
On 09 Jan 2015, at 18:21, sergio_101 <sergio.rrd@gmail.com> wrote:
I would like to do something like:
MyObject updateWIth: aDictionary.
then, inside the object, treat the keys as instance variables, and the values as values.. and do something like:
(key1 asInstanceVariable(??)): value1.
this seems like it should be possible, but i am just not getting it.
any ideas?
the magic is #instVarNamed:put: self instVarNamed: key1 put: value1 (keep in mind that this is slower than direkt access of instance variables) Marcus
perfect! speed is not a huge issue, in that this will just be a set of methods that build data one time (sort of like a rails migration) and it will not be run again.. thanks! On Fri Jan 09 2015 at 4:29:04 PM Marcus Denker <marcus.denker@inria.fr> wrote:
On 09 Jan 2015, at 18:21, sergio_101 <sergio.rrd@gmail.com> wrote:
I would like to do something like:
MyObject updateWIth: aDictionary.
then, inside the object, treat the keys as instance variables, and the values as values.. and do something like:
(key1 asInstanceVariable(??)): value1.
this seems like it should be possible, but i am just not getting it.
any ideas?
the magic is #instVarNamed:put:
self instVarNamed: key1 put: value1
(keep in mind that this is slower than direkt access of instance variables)
Marcus
participants (2)
-
Marcus Denker -
sergio_101