Re: [F-Script-talk] Dictionary and a shell command wanted :)
Brought to you by:
pmougin
From: Philippe M. <pm...@ac...> - 2006-08-25 20:18:39
|
Le 25 ao=FBt 06 =E0 21:00, Giovanni Giorgi a =E9crit : > > On 24/ago/06, at 12:07, Philippe Mougin wrote: > >> >>> NSObject subclass:'MyClass' instanceVariableNames:'a b c' >> MyClass >> >>> MyClass setFSBlock:[:self :_cmd| 'Method ' ++ _cmd ++ ' called on ' >> ++ self printString] asInstanceMethod:#method1 >> >>> myInstance :=3D MyClass alloc init >> >>> myInstance method1 >> 'Method method1 called on <MyClass: 0x4bb69c0>' >> >> Using the setFSBlock... methods you can also add methods to existing >> Cocoa classes. > Nice! > How can access to instance variable inside methods block? > I tried with (self a) > without so much success. > Even valueForKey: didn't work :| Here is an example using KVC to access instance variables: > MyClass setFSBlock:[:self| self setValue:33 forKey:'a'. self =20 valueForKey:'a'] asInstanceMethod:#method1 > myInstance method1 33 --Philippe |