On Sep 3, 2012, at 10:24 PM, Gerriet M. Denkmann <gerr...@mdenkmann.de> wrote:

> I have a class with a mutable array. But from outside it should be just a 
> read-only non-mutable array.
> My current solution:
> 
> MyClass.h file contains:
> 
> @property (readonly, nonatomic)       NSArray *externalArray;
> 
> and MyClass.m file has:
> 
> @interface MyClass()
> @property (strong)    NSMutableArray  *internalArray;
> @end
> 
> @implementation MyClass
> - (NSArray *) externalArray { return self.internalArray; }
> @end
> 
> Is there a better (more elegant) way?

Not really. Although you may want to return a copy/autoreleased array for 
-externalArray as otherwise code that uses this accessor would see future 
mutations to the internalArray.

> And another question:
> I have a struct property like:
> @property (assign)    some_Struct_t           myStruct;
> 
> But when I write:
> self.myStruct.something = 7;
> I get told "Expression is not assignable". (Xcode 4.4.1)
> 
> This works:
> some_Struct_t temp = self.myStruct;
> temp.something = 7;
> self.myStruct = temp;
> 
> But this is not really nice. There sure must be a better way.


There isn't. You get the message you get because "self.myStruct.something = 7" 
gets broken down to "[self myStruct].something = 7", but the LHS of that is not 
assignable (its an R-value, not an L-value, and only L-values are assignable).
--
David Duncan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to