• 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: Problems with NSArrayController and keyPath Operator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with NSArrayController and keyPath Operator


  • Subject: Re: Problems with NSArrayController and keyPath Operator
  • From: Scott Stevenson <email@hidden>
  • Date: Thu, 30 Nov 2006 18:13:47 -0800


On Nov 30, 2006, at 10:26 AM, Brian Williams wrote:

I still get
*** NSRunLoop ignoring exception '[<_NSFaultingMutableSet 0x320e50> addObserver:forKeyPath:options:context:] is not supported.
Key path: @distinctUnionOfObjects.payee' that raised during posting of delayed perform with target 3b5e20 and selector 'invokeWithTarget:'


I have posted an <a href="http://chromaticgray.com/ AccountsAndTransactions.zip">Example App 64kB</a> if you Scott or anyone else would be so kind to tell me what I am doing wrong.

I think I fixed it: <http://theocacao.com/downloads/AccountsAndTransactions-fixed.zip>

I want to explain this for the archives, but it's a bit tricky. Basically, Brian had a model like this:

Account
	balance - int
	name - string

Transaction
	amount - int
	payee - string

There's also a relationship between the two:

	account <-->> transactions

All of this is correct.


In the NIB, he had three controllers:

Accounts
	Entity Mode
	Entity: Account

Transactions
	Entity Mode
	Entity: Transaction

Payees
	Class Mode
	Class: NSString

The first two are just bound to a Managed Object Context, which is correct. The problem was with the third array controller, Payees. It was setup to manage an array of NSStrings with a binding like this:

Payees
	contentArray
		Bind to: Accounts array controller
		Controller key: selection
		Model key path: email@hidden

The table column the payees was bound like this:

	value
		Bind to: Payees array controller
		Controller key: arrangedObjects
		Model key path: <empty>

In other words, he was trying to get an array of payee strings in one step, then bind to it.

The problem is that NSArrayControllers has no idea how to setup a binding for a mutable set with "@distinctUnionOfObjects.payee." What would happen if you did an 'add' here, for example? Add a payee name -- to what?


All we need is the _subset_ of transactions which belong to the currently selected account. So instead of the Payees array controller, we have this:


TransactionsInAccount array controller
	Entity Mode
	Entity: Transaction

	contentSet
		Bind to: Account array controller
		Controller key: selections
		Model key path: transactions

The table column is then bound like this:

	value
		Bind to: TransactionsInAccount array controller
		Controller key: arrangedObjects
		Model key path: payee

(the array controller's name is different in the zip file I posted but the concept is the same)

So instead of having the NSArrayController fetch an array of payee names itself, we break it down into a two-step process.

1. Get the contentSet of Transactions which belong to the selected Account
2. Bind the table column to that subset and use 'payee' as the model key path


Hope that all makes sense. Imagine a bunch of exaggerated hand motions if it helps.

    - Scott

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Problems with NSArrayController and keyPath Operator
      • From: Brian Williams <email@hidden>
References: 
 >Problems with NSArrayController and keyPath Operator (From: Brian Williams <email@hidden>)
 >Re: Problems with NSArrayController and keyPath Operator (From: Scott Stevenson <email@hidden>)
 >Re: Problems with NSArrayController and keyPath Operator (From: Brian Williams <email@hidden>)

  • Prev by Date: Re: Bindings between nib files (again)
  • Next by Date: Re: Connecting to SQLITE
  • Previous by thread: Re: Problems with NSArrayController and keyPath Operator
  • Next by thread: Re: Problems with NSArrayController and keyPath Operator
  • Index(es):
    • Date
    • Thread