• 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: Local Properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Local Properties


  • Subject: Re: Local Properties
  • From: Graham Cox <email@hidden>
  • Date: Tue, 04 Sep 2012 15:52:01 +1000

On 04/09/2012, at 3:24 PM, Gerriet M. Denkmann <email@hidden> wrote:

> I have a class with a mutable array. But from outside it should be just a read-only non-mutable array.
[]

> Is there a better (more elegant) way?


Just return the internal (mutable) array as an NSArray. By typing it as an NSArray, you have documented your intent - that the returned value is immutable.

If a client of the code is caching this array, consider making THAT property a copy property.

> But when I write:
> self.myStruct.something = 7;
> I get told "Expression is not assignable". (Xcode 4.4.1)

self.myStruct needs to be on the right hand side of an assignment expression, not the left. It's equivalent to [self myStruct] which returns a value. x = self.myStruct.something is legal, but not self.myStruct.something = x;

but anyway since self.myStruct returns a copy of the struct, assigning some value to it is not going to change the copy internal to your class.

A better way to do this is to make each field of the struct a property of the object and just set it that way. Why use structs anyway? Make it an object and add the intelligence/properties there.

--Graham



_______________________________________________

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: Local Properties
      • From: Andreas Grosam <email@hidden>
References: 
 >Local Properties (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Local Properties
  • Next by Date: Re: [Moderator] Sandboxing die.die.die
  • Previous by thread: Re: Local Properties
  • Next by thread: Re: Local Properties
  • Index(es):
    • Date
    • Thread