• 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: readonly property which is a mutable array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: readonly property which is a mutable array


  • Subject: Re: readonly property which is a mutable array
  • From: "email@hidden" <email@hidden>
  • Date: Thu, 18 Nov 2010 13:20:35 +0000

On 18 Nov 2010, at 13:01, email@hidden wrote:

>
> On 18 Nov 2010, at 12:35, Remco Poelstra wrote:
>
>> Hi,
>>
>> I've a object like to following:
>> @interface <Proto> {
>> 	NSMutableArray *items;
>> }
>> @property (nonatomic,readonly) NSMutableArray *items;
>> @end
>>
>> I also have a protocol as follows:
>> @protocol Proto
>> @property (nonatomic,readonly) NSArray *items;
>> @end
>>
>> I of course want the items to be read only for the outside world, but the object itself should be able to modify it. Now the compiler complains about the properties not matching. How should I solve this? Make a custom getter that returns an immutable array? Make the property refer to a mutable array? Make the property an immutable array and make copies of the array while modifying it?
>> Any insight would be appreciated.
>>
>
> Define a class extension (an unnamed category) within your implementation .m file:
>
> @interface <Proto> ()
> @property (nonatomic. readwrite) NSMutableArray *items;
> @end
>
> Your object will have readwrite access.
>
> See http://www.friday.com/bbum/2009/09/11/class-extensions-explained

Sorry. Wrong answer. Didn't read the question properly.

Don't make items a property if you don't want to advertise it to the outside world.

I would have a custom getter called items which returns [items copy].
When you modify items raise manual KVO notifications to inform observers of your changes.

Jonathan_______________________________________________

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: 
 >readonly property which is a mutable array (From: Remco Poelstra <email@hidden>)
 >Re: readonly property which is a mutable array (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: readonly property which is a mutable array
  • Next by Date: Re: Core Data: During Migration, should use Primitive Accessors only?
  • Previous by thread: Re: readonly property which is a mutable array
  • Next by thread: Re: readonly property which is a mutable array
  • Index(es):
    • Date
    • Thread