• 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: Using fake properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using fake properties


  • Subject: Re: Using fake properties
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 17 Aug 2013 00:51:23 -0500

On Aug 17, 2013, at 12:31 AM, Gerriet M. Denkmann wrote:

> Currently I have stuff like:
>
> 	#if 		TARGET_OS_IPHONE
> 		NSLayoutManager *layoutManager = self.textView.layoutManager;
> 	#else	//	TARGET MAC OS X
> 		NSLayoutManager *layoutManager = [ self.textView layoutManager ];
> 	#endif	//	TARGET
>
> But I noticed that OS X also accepts:
> 	layoutManager = self.textView.layoutManager;
>
> 1. Is this a save idiom to use?

Yes.

> 2. If so, is it a good idea to treat method calls like properties?

It's a good idea to treat properties like properties.  See below…

> 3. If so, why doesn't NSTextView not declare this method as a (readonly) property?

Properties existed well before _declared propreties_ (@property) were added to the language.  The declaration of a getter method defines a readable property.  The further declaration of a setter defines a read-write property.  There's no need for an @property declaration.  @property is a shortcut – it declares the accessor methods for you – plus some goodies: it gives some additional information about semantics like ownership policy.  The Objective-C runtime is aware of declared properties (i.e. class_copyPropertyList()).  In the implementation (which you shouldn't care about for classes other than your own), the compiler can use a declared property to synthesize instance variables and the accessors.

All of that is separate from dot syntax.  Dot syntax is just syntactic sugar for accessing properties through the accessors.  All properties, not just declared properties.

NSTextView does declare layoutManager as a property.  It just does so in the old way, using a getter method, rather than a declared property, using @property.  Either way, you can safely use dot syntax to access that property.

Regards,
Ken


_______________________________________________

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: Using fake properties
      • From: Quincey Morris <email@hidden>
References: 
 >Using fake properties (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Using fake properties
  • Next by Date: Re: Using fake properties
  • Previous by thread: Using fake properties
  • Next by thread: Re: Using fake properties
  • Index(es):
    • Date
    • Thread