Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-28 Thread Siavash
Coming from a Flex/Flash background I will have to say that there is  
BIG differences between ActionScript 2.0 and 3.0. AS 3.0 is a powerful  
OOP language and AS 2.0 is not. That being said, the same object  
oriented principles do apply in ActionScript 3.0 the same as Obj-C and  
the Cocoa Framework. I would say a good tutorial/book on MVC structure  
would clear up some things. Also obj-c is not as forgiving as  
ActionScript syntax wise.  I could see the difficulty coming from  
Flash IDE into Cocoa. I think the transition is a little easier for a  
Flex Developer. Many mx.controls.* UI classes are similar to Cocoa UI  
classes except instead of listening for events you have targets,  
selectors, and delegates.

--

Siavash Ghamaty


On Oct 27, 2008, at 8:40 PM, Graham Cox wrote:



On 28 Oct 2008, at 2:30 pm, john fogg wrote:


I come from coding in Actionscript (Flash) and there things are
apparently quite different.



FWIW, I tried to do some coding in Actionscript a few years ago  
after being immersed in C++ for many years and then Objective-C/ 
Cocoa for a few years. To say that it was an exercise in utter  
frustration is an understatement. As a programmer in these real  
languages I found AS to be really mickey-mouse.


Others' opinions will no doubt vary but I suspect that if you know  
AS well, moving to what I call a real language is going to mean  
unlearning a huge heap of rubbish. Sorry, just my opinion.


--Graham
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/coldsweat%40gmail.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread john fogg
Hi again!

I'm still plucking along and any help is still greatly appreciated!

Here is the deal: I create a subobject called mySubObject inside my
main object myMainObject. Now I want to access myMainObject from
within mySubObject.

I'm still not sure what the ideal way to do this would be but I have
gotten it to work somehow. Inside myMainObject I create a property
and point it to self so it stores a reference to myMainObject.
Inside mySubObject I cannot access this by writing

[pointerToMainObject doMethod];

but it works when I write

[self.pointerToMainObject doMethod];

Why? What difference does self make here?

I'm still trying to wrap my head around all this stuff so please bear
with me here. :-)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread Nick Zitzmann


On Oct 27, 2008, at 8:35 PM, john fogg wrote:


Inside mySubObject I cannot access this by writing

   [pointerToMainObject doMethod];

but it works when I write

   [self.pointerToMainObject doMethod];

Why? What difference does self make here?



Because the latter accesses the property of self, and the former  
doesn't. Assuming you're not developing exclusively for 64-bit (the 64- 
bit runtime supports properties without synthesis or implementations,  
IIRC), then using the original pointer variable in place of the former  
ought to work.


Nick Zitzmann
http://www.chronosnet.com/



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread John Velman
I'm new to objective-C and cocoa also, I I don't know the answer to your
specific question about self.  However, seems that one way to do it would
be to have the init of mySubObject have an initializer with argument, and
you would then create it something like this:

SubObject * mySubObject = [[SubObject alloc] initWithParent:self]

This save puting a variable set to 'self' inside MainObject.

Best,

John V.

On Tue, Oct 28, 2008 at 03:35:55AM +0100, john fogg wrote:
 Hi again!
 
 I'm still plucking along and any help is still greatly appreciated!
 
 Here is the deal: I create a subobject called mySubObject inside my
 main object myMainObject. Now I want to access myMainObject from
 within mySubObject.
 
 I'm still not sure what the ideal way to do this would be but I have
 gotten it to work somehow. Inside myMainObject I create a property
 and point it to self so it stores a reference to myMainObject.
 Inside mySubObject I cannot access this by writing
 
 [pointerToMainObject doMethod];
 
 but it works when I write
 
 [self.pointerToMainObject doMethod];
 
 Why? What difference does self make here?
 
 I'm still trying to wrap my head around all this stuff so please bear
 with me here. :-)
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/cocoa-dev/velman%40cox.net
 
 This email sent to [EMAIL PROTECTED]
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread Ken Thomases

On Oct 27, 2008, at 9:35 PM, john fogg wrote:


Here is the deal: I create a subobject called mySubObject inside my
main object myMainObject. Now I want to access myMainObject from
within mySubObject.


Your terminology is a bit hard to follow.  Part of the problem is that  
object's don't have names, they have addresses.  Object pointer  
variables have names and can contain the addresses of objects.  But  
the pointer isn't the object and the object isn't the pointer.   
Understanding this is important, since you seem to be foggy on how the  
two concepts interact.  A pointer can change which object it's  
pointing to over time.  An object may be pointed to by many different  
pointers, which will have different names.


And you don't write code or define properties inside objects.  You  
define them in (or for) classes.


So, when you say I create a subobject called 'mySubObject' inside my  
main object 'myMainObject' I translate that to mean, that you have a  
pointer named myMainObject to an instance of some custom class.  In  
the implementation of that class, there's a method, and in that method  
you create another object of some other(?) class and store its address  
into a pointer named mySubObject.  mySubObject might be a local  
variable, an instance variable, or whatever.


Now, what does within 'mySubObject' mean?  I assume you mean within  
an instance method of the class of which mySubObject is an instance.


OK.

In the method of the first class -- the class of myMainObject; where  
you created mySubObject -- you can pass 'self' to mySubObject as a  
message parameter.  It might be a parameter of the init message (- 
initWithOwner:, for example), or you might use a setter (e.g. - 
setOwner:).  The second class -- the class of mySubObject -- would  
keep track of the owner in one of its instance variables, possibly  
called owner.  Then, when it wanted to message its owner, it could  
do [owner someMethod] or owner.someProperty, etc.




I'm still not sure what the ideal way to do this would be but I have
gotten it to work somehow. Inside myMainObject I create a property
and point it to self so it stores a reference to myMainObject.


Is that a typo?  You have created a property on an object which refers  
to itself?  That doesn't make sense to me.


(Again, the property isn't inside myMainObject.  It's inside the class  
from which myMainObject was instantiated.)




Inside mySubObject I cannot access this by writing

   [pointerToMainObject doMethod];

but it works when I write

   [self.pointerToMainObject doMethod];

Why? What difference does self make here?


That doesn't seem sensible to me.  However, without seeing the code in  
question, it's very hard to tell what might be happening.  Seeing the  
code would also probably clarify what you're trying to say.


Cheers,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread john fogg
Ken Thomases wrote me off-list. I don't know if this was deliberate (I
guess not) but I'd rather not quote his mail here without his consent.

Anyways the problem is fixed and I understand it all a whole lot
better now. Big thanks to everybody and esp. Ken. You all are very
nice people!!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread john fogg
Hi Ken!

Thank you for your long answer! It cleared up a lot of things for me.
I come from coding in Actionscript (Flash) and there things are
apparently quite different.

Is it true that all instances I create live in memory on the same
level? That they are all somehow equal? And that all relationships
between them are only by pointers?
Because in Actionscript you can have instances inside other object's
instances and once you dealloc the containing instance all the other
object's instances it contained die with it. Think Matryoshka puppets
or something like that.

On 10/28/08, Ken Thomases [EMAIL PROTECTED] wrote:

 Part of the problem is that object's don't have names, they have addresses.

I see. So I can only access an instance from within some other
instance if I always remember to pass along a pointer to it?

 But the pointer isn't the object and the object isn't the pointer.

This is what I got wrong I guess.

 So, when you say I create a subobject called 'mySubObject' inside my
 main object 'myMainObject' I translate that to mean, that you have a
 pointer named myMainObject to an instance of some custom class.  In
 the implementation of that class, there's a method, and in that method
 you create another object of some other(?) class and store its address
 into a pointer named mySubObject.  mySubObject might be a local
 variable, an instance variable, or whatever.

 Now, what does within 'mySubObject' mean?  I assume you mean within
 an instance method of the class of which mySubObject is an instance.

Thank you. You translated correctly and explained it to me at the same time! :-)

Your following explanation did the trick for me. Thank you again!

Cheers, John.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread Graham Cox


On 28 Oct 2008, at 2:30 pm, john fogg wrote:


I come from coding in Actionscript (Flash) and there things are
apparently quite different.



FWIW, I tried to do some coding in Actionscript a few years ago after  
being immersed in C++ for many years and then Objective-C/Cocoa for a  
few years. To say that it was an exercise in utter frustration is an  
understatement. As a programmer in these real languages I found AS  
to be really mickey-mouse.


Others' opinions will no doubt vary but I suspect that if you know AS  
well, moving to what I call a real language is going to mean  
unlearning a huge heap of rubbish. Sorry, just my opinion.


--Graham
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Why self? (Was: Newbie: Referencing Objects)

2008-10-27 Thread john fogg
Hi Graham!

On 10/28/08, Graham Cox [EMAIL PROTECTED] wrote:

 FWIW, I tried to do some coding in Actionscript a few years ago after
 being immersed in C++ for many years and then Objective-C/Cocoa for a
 few years. To say that it was an exercise in utter frustration is an
 understatement. [...]

I think I know how you feel. :-) And I share your opinion about
Actionscript and (for me) Flash in general. I feel kinda spoiled by
Actionscript but I'm unlearning now. :-))
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]