Alex Rivera | Logout

Does @property copy in combination with readonly make sense?

Asked 2012-02-22T15:05:20.337
36

If I understand this correctly, copy enforces the setter to create a copy of the object passed in. However, if I use it together with readonly, there won't be a setter. So is my assumption correct, that combining @property (copy, readonly) doesn't make any sense or am I missing something?

Edit
Report

1 Answer

-2

I think, if I saw such a property, on read, I would expect to receive a distinct returned object to the ivar unless the returned object was advertised to be immutable.

If I have

@property (readonly, copy) NSMutableArray* foo;

and I do this:

NSMutableArray* myFoo = [theObject foo];
[myFoo addObject: @"string"];
NSMutableArray* myOtherFoo = [theObject foo];

I would expect myOtherFoo not to have the extra string in it that myFoo has.

Note: I haven't verified this yet.

I have checked it now and my expectation is incorrect. I think I would regard that as a bug.

answered 2012-02-22T15:15:47.080

Your Answer