• 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: Understanding the "declaration of instance variables in the interface is deprecated" warning.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.


  • Subject: Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.
  • From: Britt Durbrow <email@hidden>
  • Date: Wed, 03 Jun 2015 17:36:12 -0700

> On Jun 3, 2015, at 11:30 AM, Mark Wright <email@hidden> wrote:
>
> For what it’s worth, I’ve never had that problem either.  Most of the time self.whatever is used for property access, _whatever is used for ivar access and that’s about it.

Yup. This is what I meant about properties vs ivars being obvious from context: the only way to do a property access is by causing a message send; and there are only three direct ways to do that in Objective-C: somePointer.accessor (i.e, dot notation); [somePointer accessor] and [somePointer setAccessor:aNewValueGoesHere]; and a direct call to objc_msgSend().

All other forms are direct variable access: either globals, locals, or instance variables.

In other words:

@inteface foo : NSObject
	@property(nonatomic) int bar;
	-(void)doSomething;
@end

@implementation foo
{
	int bar;
};

-(int)bar
{
	return bar;
};

-(void)setBar:(int)new_BarValue
{
	bar=new_BarValue;
};

-(void)doSomething
{
	bar=12345;		// Direct access to bar

	self.bar=12345	// Going thru the property’s setter
	[self setBar:6789];
	if([self bar]==6789)
		puts(“Yay, it’s still what I set it to!\n”);

	int baz;			// Obviously a local

	baz=123			// Direct access

	self.baz=456;		// Compile error here; because baz is a local, not a property. Other obvious error patterns left as an exercise for the reader. :-)
};

@end

// Note: thoroughly compiled and tested in Mail.app ;-)
_______________________________________________

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


  • Follow-Ups:
    • Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.
      • From: Uli Kusterer <email@hidden>
References: 
 >Re: Understanding the "declaration of instance variables in the interface is deprecated" warning. (From: Mark Wright <email@hidden>)
 >Re: Understanding the "declaration of instance variables in the interface is deprecated" warning. (From: Uli Kusterer <email@hidden>)
 >Re: Understanding the "declaration of instance variables in the interface is deprecated" warning. (From: Alex Zavatone <email@hidden>)
 >Re: Understanding the "declaration of instance variables in the interface is deprecated" warning. (From: Uli Kusterer <email@hidden>)
 >Re: Understanding the "declaration of instance variables in the interface is deprecated" warning. (From: Mark Wright <email@hidden>)

  • Prev by Date: Re: Questions about NSPopupButtonCell and NSBrowser
  • Next by Date: Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.
  • Previous by thread: Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.
  • Next by thread: Re: Understanding the "declaration of instance variables in the interface is deprecated" warning.
  • Index(es):
    • Date
    • Thread