List Info

Thread: How to use nib outlets/connections with Objective-C bridge




How to use nib outlets/connections with Objective-C bridge
user name
2006-10-30 09:35:54

--- In iolanguage%40yahoogroups.com">iolanguageyahoogroups.com, "baptisteheyman"
<baptisteheyman...> wrote:
&gt;
>
> --- In iolanguage%40yahoogroups.com">iolanguageyahoogroups.com, Quentin Mathé
>; <gnustep-quentin> wrote:
&gt; >
> > Le 29 oct. 06 à 12:39, baptisteheyman a écrit :
> >
> > > --- In iolanguage%40yahoogroups.com">iolanguageyahoogroups.com, Quentin Mathé gnustep-quentin
> > > wrote:
&gt; > > >
> > > > Le 27 oct. 06 à 19:17, Quentin Mathé a écrit :
> > >
> > > > How do I proceed to add new slots which aren't methods but rather
&gt; > > > instance variables?
> > > >
> > > > I tried without success:
> > > >
> > > > NSObject newSubclassNamed:(&quot;Controller") do(
> > > > setTableView: := method(sender, self tableView := sender)
&gt; > > > setWindow: := method(sender, self window := sender)
&gt; > > > myVar := "whatever"
> > > > )
> > > >
> > > > I replaced myVar := "whatever" by a setSlot, updateSlot or newSlot
&gt; > > > call without success either. Another thing I tried is to put in
> the
> > > > slot an NSString or a nil value rather an Io string.
&gt; > > > Is this problem related to the fact we cannot add instance
> variables
> > > > on the fly on Objc side?
>; > >
> > > I had added a method to create instance variable from Io side, but i
> > > finally removed it because i thought it could be problematic for the
> > > heritage on the Objective-C side.
>; >
> > ok.
> >
> > > An Objective-C object allocates memory for its instance variables
> and
> > > its ancestors instance variables, so what would happen if you added
>; an
> > > instance variable to an ancestors ? That's why categories don't
>; allow
>; > > extra variables either.
&gt; >
> > But at the time you create the subclass, I think you can create
&gt; > whatever instance variables you need and pass them by adding a new
> > parameter to newSubclassNamed. Then the runtime call in charge of
> > subclassing will take care of them. However it won't be possible to
> > create new slots/ivars later or in another way as it's common with
> > Io. What do you think?
&gt; >
> > > To make your Io variable visible on the Objective-C side you could
>; > > just add getter/setter methods.
> > >
> > > NSObject newSubclassNamed:(&quot;Controller") do(
> > > setTableView: := method(sender, self tableView := sender)
&gt; > > setWindow: := method(sender, self window := sender)
&gt; > > _myVar := "whatever"
> > > myVar := method(_myVar)
> > > setMyVar: := method(value, _myVar = value)
&gt; > > )
> >
> > I will try that.
>; > Another thing which might work well is… Declaring an Objc class
>; named
>; > AbstractController which includes ivar declartions in its interface.
> > Then calling AbstractController newSubclassNamed:(&quot;Controller") do
> > (... In this case, the outlets would be inherited from the superclass.
> >
> > I have a last question. What is the best way to link/load an Objc
> > framework? By linking it in a bundle and loading the bundle?
&gt; >
> > Thanks,
&gt; > Quentin.
> >
> > --
> > Quentin Mathé
>; > qmathe
> >
>
> Yes, we could just add instance variables at class creation, but how
> would you access them from Io then ? We still need getter/setter methods
&gt; so we're stuck unless we allow direct access to Objective-C instance
> variables. It is feasible, it was even implemented but it was really not
> needed, sharing methods between Io and Objective-C is sufficient.
>
> For your last question, well, i'm not sure to get what you want, do you
> want to load non GNUstep Objective-C code ? If so, bundle loading should
&gt; do the trick, else you could hack the ObjcBridge build.io and add the
> dependsOnLib/dependsOnFramework line you need. Anyway if your code
> declare an informal protocol (not compiler enforced methods) you should
&gt; add it at the end of IoObjcBridge.h and in
> IoObjcBridge_selectorEncoding. Do you want a standalone compiled program
&gt; or a script like in
> http://www.etoile-project.org/etoile/blog/2006/09/io-and-gnustep.html ?
>

The _myVar := "whatever" will in fact never work that way, _myVar
being created in the proto but never added in the object itself, you
could see it as a class variable accessible through Controller _myVar,
so to add an instance variable you need an instance self, for example
in the init method

NSObject newSubclassNamed:(&quot;Controller") do(
setTableView: := method(sender, self tableView := sender)
setWindow: := method(sender, self window := sender)
init := method(self = super(init) ; self _myVar := "whatever" ;
self)
myVar := method(_myVar)
setMyVar: := method(value, _myVar = value)
)

An even better method is to add an addVariableNamed: method which
would be put in an Io/addons/ObjcBridge/io/ObjcBridge.io file

Object addVariableNamed: := method(name,
self setSlot(name, doString(&quot;method(?_" .. name .. ")&quot;))
self setSlot(&quot;set&quot; .. name asCapitalized .. ":&quot;,
doString("method(value, self _" .. name .. " := value ; self)";))
nil
)

Your test program would then become

NSObject newSubclassNamed:(&quot;Controller") do(
addVariableNamed:("tableView&quot;)
addVariableNamed:("window";)
)

automatically creating accessor methods to two "private" variables
_tableView and _window.

Hope it was understandable

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )