Re: readonly property which is a mutable array

2010-11-19 Thread Remco Poelstra
Op 19-11-2010 3:51, Ken Thomases schreef: 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

Re: readonly property which is a mutable array

2010-11-19 Thread jonat...@mugginsoft.com
On 19 Nov 2010, at 02:51, Ken Thomases wrote: You don't need to implement the getter. The Cocoa docs are very clear that callers must respect the declared type of properties (i.e. return type of getters). That is, if the getter is declared to return an immutable NSArray, then

Re: readonly property which is a mutable array

2010-11-19 Thread Andreas Grosam
On Nov 19, 2010, at 10:29 AM, jonat...@mugginsoft.com wrote: If I receive an NSArray instance from a method I can for example identify the index of a particular object within the array, say at idx, safe in the knowledge that my object is at the given index. If however the object I

Re: readonly property which is a mutable array

2010-11-19 Thread Keary Suska
On Nov 18, 2010, at 7:51 PM, Ken Thomases wrote: On Nov 18, 2010, at 9:33 AM, Keary Suska wrote: On Nov 18, 2010, at 5:35 AM, Remco Poelstra wrote: Hi, I've a object like to following: @interface Proto { NSMutableArray *items; } @property (nonatomic,readonly) NSMutableArray

Re: readonly property which is a mutable array

2010-11-19 Thread David Duncan
On Nov 19, 2010, at 10:00 AM, Keary Suska wrote: So, I think we should write code to guarantee immutability to the caller, regardless of type of course, which is the API contract you spell out. I see the easiest way as always returning a copy in the getter. But I don't remember how

readonly property which is a mutable array

2010-11-18 Thread Remco Poelstra
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

Re: readonly property which is a mutable array

2010-11-18 Thread jonat...@mugginsoft.com
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)

Re: readonly property which is a mutable array

2010-11-18 Thread jonat...@mugginsoft.com
On 18 Nov 2010, at 13:01, jonat...@mugginsoft.com 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

Re: readonly property which is a mutable array

2010-11-18 Thread Keary Suska
On Nov 18, 2010, at 5:35 AM, 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)

Re: readonly property which is a mutable array

2010-11-18 Thread Ken Thomases
On Nov 18, 2010, at 9:33 AM, Keary Suska wrote: On Nov 18, 2010, at 5:35 AM, 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: