swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: obj->


From: Nelson Minar
Subject: Re: obj->
Date: Wed, 19 Jun 96 18:16:48 MDT

>In HeatbugsModelSwarm.m some variables are initialized using obj->
>and others just using the .h file reference.  I notice that
>the dividing line seems to be whether they are a pointer or id,
>or some other data type but it is unclear to me why this is so.
>Are the two different ways necessary and why?  

The obj-> notation is a shorthand. Objects in Objective C are structs,
so if you know the full type of the object you can use struct notation
to access it. Swarm programs don't normally do this, for various good
reasons.

But this is a special case: class HeatbugModelSwarm has just built an
instance of itself and is now initializing it's default values. Say
you have a class with the variable "numBugs". In a normal method for
that class, you can write code that says
  numBugs = 50;
and it works. In fact, implicitly this is
  self->numBugs = 50;

In the special case of +createBegin, "self" isn't set to the object
being created - because it hasn't been created yet. So the createBegin
method in HeatbugModelSwarm creates the object and then does the
struct references to set the values.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]