• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why "self"? (Was: Newbie: Referencing Objects)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Why "self"? (Was: Newbie: Referencing Objects)
  • From: John Velman <email@hidden>
  • Date: Mon, 27 Oct 2008 19:49:00 -0700

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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Re: Why "self"? (Was: Newbie: Referencing Objects) (From: "john fogg" <email@hidden>)

  • Prev by Date: Re: Why "self"? (Was: Newbie: Referencing Objects)
  • Next by Date: accessing menu crashes app
  • Previous by thread: Re: Why "self"? (Was: Newbie: Referencing Objects)
  • Next by thread: Re: Why "self"? (Was: Newbie: Referencing Objects)
  • Index(es):
    • Date
    • Thread