• 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: Newbie Question on "self"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Question on "self"


  • Subject: Re: Newbie Question on "self"
  • From: Jonathan Hess <email@hidden>
  • Date: Mon, 11 Aug 2008 10:59:28 -0700


On Aug 11, 2008, at 10:47 AM, Matt Keyes wrote:

Hello again,

In C/C++ and the .NET languages I am used to, I have generally tried to prefix any member variables inside class methods with "this"

i.e. this.m_sMyString = "this is my string";

In Objective-C, this doesn't seem as clear to me (or at least it doesn't compile). For example:

- (id)initWithString:(NSString *) string {
   self.myString = [[NSString alloc] initWithString:string];
}

Hey Matt -

If you prefer this type of explicit reference to an instance variable, this syntax will work:

self->myString = [[NSString alloc] initWithString:string];

Since self is a pointer, you need to use the -> operator. If you're familiar with working with structure members, object members work the same way. The . syntax only applies if you have an actual object instead of a pointer to an object, which you'll really never have in objective-c.

Good Luck -
Jon Hess



Produces an error:

error: request for member 'myString' in something not a structure or union

I am sure this is something very simple and basic I am missing, but any assistance is appreciated.

Thanks,
Matt

_________________________________________________________________
Get Windows Live and get whatever you need, wherever you are. Start here.
http://www.windowslive.com/default.html?ocid=TXT_TAGLM_WL_Home_082008_______________________________________________


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: 
 >Newbie Question on "self" (From: Matt Keyes <email@hidden>)

  • Prev by Date: Re: Newbie Question on "self"
  • Next by Date: Re: NSConditionLock vs MPQueue
  • Previous by thread: Re: Newbie Question on "self"
  • Next by thread: Re: Newbie Question on "self"
  • Index(es):
    • Date
    • Thread