• 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: @property and automatic synthesis of getters and setters.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @property and automatic synthesis of getters and setters.


  • Subject: Re: @property and automatic synthesis of getters and setters.
  • From: John Pannell <email@hidden>
  • Date: Thu, 12 Sep 2013 15:56:00 -0600

Hi Peter-

For the declared property "protoCell", automatic synthesis is going to make an instance variable named "_protoCell".  You can then refer to it in an instance method as either:

1.  _protoCell - direct ivar access.
2.  self.protoCell - access through the getter.

The reference to protoCell alone is neither of the above, and you'll get the warning.  I seem to recall that best practice in an init method is to directly access the ivar.

HTH!

John

On Sep 12, 2013, at 3:45 PM, Peter Teeson <email@hidden> wrote:

> Xcode 4.6.2 Lion 10.7.5
> Programming with Objective-C seems to indicate I can do this:
> #import <Cocoa/Cocoa.h>
> #import "Cell.h"  //My sub-class
>
> @interface Document : NSDocument
> @property Cell *protoCell;
> @end
>
> and  this (i.e. no need to @synthesize):
>
> @implementation Document
> - (id)init
> {
>    self = [super init];
>    if (self) {
>        protoCell = [[Cell alloc]init];
>        // Add your subclass-specific initialization here.
>    }
>    return self;
> }
> ……
> @end
>
> but the compiler tells me
> Use of undeclared identifier 'protoCell'; did you mean '_protoCell'?
>
> If I do refer to the ivar using the internal reserved form _protoCell
> the compiler is happy.
>
> What is my lack of understanding? Why am I not allowed to use
> the getter protoCell as indicated in the documentation?
>
> TIA
>
> Peter
> _______________________________________________
>
> 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: 
 >@property and automatic synthesis of getters and setters. (From: Peter Teeson <email@hidden>)

  • Prev by Date: Re: @property and automatic synthesis of getters and setters.
  • Next by Date: Re: @property and automatic synthesis of getters and setters.
  • Previous by thread: Re: @property and automatic synthesis of getters and setters.
  • Next by thread: quitting app running in status bar logs this message about some modal session
  • Index(es):
    • Date
    • Thread