• 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: @properties and Information Hiding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @properties and Information Hiding


  • Subject: Re: @properties and Information Hiding
  • From: Milo Bird <email@hidden>
  • Date: Thu, 1 Nov 2007 14:30:56 +0000

You can declare a property readonly in your interface, and then re- declare it as readwrite in a private category or class extension. Here's what the Objective-C 2.0 docs say:
You can re-declare a property in a subclass, but (with one exception) you must repeat its attributes in whole in the subclasses. The same holds true for a property declared in a category or protocol—while the property may be redeclared in a category or protocol, the property’s attributes must be repeated in whole.

The one exception is readonly vs. readwrite. A property declared as readonly can be redeclared as readwrite in a category, protocol or subclass—see “Subclassing with Properties.” In the case of a category redeclaration, that the property was redeclared prior any @synthesize statement will cause the setter to be synthesized.


The only problem with this is that you can't re-declare any of the other declaration attributes. This means that if you want to use the "retain" or "copy" style of accessor, rather than the default "assign", you have to declare this in the interface. This annoys me - it obviously doesn't make a lot of sense to declare a property as (readonly, copy) in the interface, but as far as I can tell that's exactly what you have to do.


Milo_______________________________________________

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: @properties and Information Hiding
      • From: Charles Steinman <email@hidden>
References: 
 >@properties and Information Hiding (From: Karl Goiser <email@hidden>)

  • Prev by Date: Re: [Leopard] Core Data model versioning vs. NSPersistentDocument
  • Next by Date: NSMailDelivery now in deprecation w/Leopard
  • Previous by thread: @properties and Information Hiding
  • Next by thread: Re: @properties and Information Hiding
  • Index(es):
    • Date
    • Thread