• 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: Making an array property without a backing store. How?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making an array property without a backing store. How?


  • Subject: Re: Making an array property without a backing store. How?
  • From: Greg Parker <email@hidden>
  • Date: Mon, 06 Apr 2015 22:37:20 -0700

> On Apr 6, 2015, at 7:01 PM, Daryle Walker <email@hidden> wrote:
>
> I have an object like:
>
> @interface MyClass : NSObject
> @property (readonly) NSArray *  myDatumList;
> @property NSArray *  myDataList;
> @end
>
> The second member is meant to be an actual data member, an array of mutable dictionaries. The first member isn’t supposed to have a backing store; accessing a member of the first array references the corresponding member of the second, then access a dictionary attribute with a custom key.
>
> I have a custom array count and array element read methods for the first member.
>
> The program does nothing now. I checked with my limited debugging skills that the second member has one element, but the first member is looped though as if it has no elements. I see that BOTH “_myDatumList” and “_myDataList” internal members exist, with the former set as NIL. I’ve heard that we used to need to use the “@synthesize” command to create internal members, then a later version of the Objective-C compiler did it automatically. Now I have the reverse problem; the first member gets a backing store automatically, but I do NOT want that; I always want to use the custom array accessor methods to simulate “myDatumList” with pieces of “myDataList.”
>
> So, how can I turn off auto-@synthesize? Using “@dynamic” doesn’t work; it causes a crash due to a missing [MyClass myDatumList] method.

@dynamic turns off automatic property synthesis. The compiler will not create ivar storage nor accessor methods for an @dynamic property.

Did you implement the method -[MyClass myDatumList] ? If you don't synthesize the property then you need to write its accessor methods yourself.


> I also saw a random page saying that “self.myDatumList” causes this, but “myDatumList” wouldn’t (like the “self.” gives the unwanted backing store have priority over the array accessor methods). Is that accurate?

`self.property` reads or writes the property via its accessor methods. `ivar` or `self->ivar` accesses an instance variable's storage directly, bypassing any property accessor methods (synthesized or not) that use that storage. If you have a property and an ivar with the same name then `self.property` and `property` will both be legal and will behave differently.


--
Greg Parker     email@hidden     Runtime Wrangler



_______________________________________________

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: 
 >Making an array property without a backing store. How? (From: Daryle Walker <email@hidden>)

  • Prev by Date: Re: Where is my bicycle?
  • Next by Date: Re: Making an array property without a backing store. How?
  • Previous by thread: Re: Making an array property without a backing store. How?
  • Next by thread: Assuring KVO compliance.
  • Index(es):
    • Date
    • Thread