• 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: "I. Savant" <email@hidden>
  • Date: Mon, 11 Aug 2008 13:54:56 -0400

> 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

  Several things:

1 - Using the dot syntax (a feature of Objective-C 2.0) requires that
you have proper accessors set up for the property you're using. In
this case, the "myString" property. Do you?

2 - In your -initWithString: method, you probably want:
self.myString = string;
  ... in your version, you're uselessly creating a string from the
passed string when the passed string will do. If you waned a copy of
the passed string, the property is where you'd specify this behavior
(ie, copy versus retain, etc.).

--
I.S.
_______________________________________________

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: Newbie Question on "self"
  • Next by Date: Re: Newbie Question on "self"
  • Previous by thread: Newbie Question on "self"
  • Next by thread: Re: Newbie Question on "self"
  • Index(es):
    • Date
    • Thread