• 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: NSArrayController - error inserting object at arranged object index N
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController - error inserting object at arranged object index N


  • Subject: Re: NSArrayController - error inserting object at arranged object index N
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 24 Jun 2016 09:35:09 -0700
  • Feedback-id: 167118m:167118agrif8a:167118sqZWfVPZxk:SMTPCORP

On Jun 24, 2016, at 03:12 , Jonathan Mitchell <email@hidden> wrote:
>
> The downside would be having to implement the compliant accessor methods in the real model object (in my case the array is a constructed property of an NSViewController subclass which obtains its array data from a non native Obj-C model)

It’s not much of a downside once you get to this point. You can do it either the easy way or the good way:

a. If you have a NSMutableArray instance variable with the name of the property (with or without a leading underscore), the ‘mutableValueForKey:’ mechanism will access it automatically, and you don’t have to write any code. This supposes that you did not set ‘accessInstanceVariablesDirectly’ to NO for the class that has the array property.

b. You can write just the ‘insert…’ and ‘remove…’ accessor methods. The trick is to define the @property first, and then use autocomplete (typing ‘insert’ and ‘remove’) to get the correct method signature written for you — I can never remember it without looking it up otherwise. The method implementations can be as short as 1 line.

For case (b), I also tend to provide an extra piece that hides the ‘mutableValueForKey:’ part. I declare the property this way:

	@property (readonly) NSArray* myProperty;
	@property (readonly) NSMutableArray* mutableMyProperty; // <— simply returns ‘[self mutableArrayValueForKey: @“myProperty”]'

Note that these are both readonly, to avoid giving client code accidental readwrite access to the instance variable that backs the property. However, you don’t really need this is the access mechanism is via KVC (e.g. bindings). It’s more of a convenience for client code.

_______________________________________________

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: 
 >NSArrayController - error inserting object at arranged object index N (From: Jonathan Mitchell <email@hidden>)
 >Re: NSArrayController - error inserting object at arranged object index N (From: Jonathan Mitchell <email@hidden>)
 >Re: NSArrayController - error inserting object at arranged object index N (From: Quincey Morris <email@hidden>)
 >Re: NSArrayController - error inserting object at arranged object index N (From: Jonathan Mitchell <email@hidden>)
 >Re: NSArrayController - error inserting object at arranged object index N (From: Quincey Morris <email@hidden>)
 >Re: NSArrayController - error inserting object at arranged object index N (From: Jonathan Mitchell <email@hidden>)

  • Prev by Date: Re: NSArrayController - error inserting object at arranged object index N
  • Next by Date: How to pre-select a file in NSOpenPanel -- specifically, a .app bundle?
  • Previous by thread: Re: NSArrayController - error inserting object at arranged object index N
  • Next by thread: unnamed function586 $$ AMDRadeon X4000GLDriver
  • Index(es):
    • Date
    • Thread