Re: Newbie Question on "self"
Re: Newbie Question on "self"
- Subject: Re: Newbie Question on "self"
- From: Gregory Weston <email@hidden>
- Date: Mon, 11 Aug 2008 14:21:10 -0400
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];
}
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.
The short answer is: self is a pointer.
The longer answer is a question: Why do you do this? Do your naming
conventions not make clear that something is an instance variable?
_______________________________________________
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