Search code examples
cocoaxcodemacoscore-datansarraycontroller

Two NSArrayControllers and a relationship (CoreData)


Is it okay to do it like i did … ?

  1. Created nsarraycontroller in entity mode controlling 'Accounts'
  2. Created nsarraycontroller in entity mode controlling 'Transactions' and bound to the 'Accounts' nsarraycontroller with key 'selection' and model key path 'transactions' (to-many relationship from accounts to transactions)

I'm askin cause i think something is kinda messed up. Because when i create a button, and try to connect it with the add:(id)sender of the transactionsArrayController, it doesn't seem to add it ... Where can be the problem ? addObject works as expected. But I want to use add:(id)sender and also be sure the code is working as it has to ...


Solution

  • Yes, it's quite normal to base the contents of one array controller on some property of another (including selection.someCollection).

    Do you receive any errors in the console when you add? (Hint: include them in your question) Are both array controllers' Managed Object Contexts bound to a valid MOC? What are all your other settings for both array controllers set to? (Another hint: you need to be a lot more specific about describing your setup.)