Re: Core data model, bindings advice.
Re: Core data model, bindings advice.
- Subject: Re: Core data model, bindings advice.
- From: Steven Huey <email@hidden>
- Date: Wed, 14 May 2008 07:53:58 -0400
Steven,
On May 13, 2008, at 5:12 AM, Steven Hamilton wrote:
How would I best handle translating the data from the entity model
to the view model? I see two options;
1) Munge around with Valuetransformers. If toAccount = selected
account then credit = amount, debit = blank, opposite if fromAccount
= selected account. I still have the add: issue.
I don't think this is the intended purpose of ValueTransformers.
3) Would a filter be more appropriate? Is it possible to filter the
transaction list and use the account selection (from the tree view)
in the filter predicate?
Take a look at NSPredicate. If you have your entities in an NSArray
you should be able to filter that using an NSPredicate in memory very
quickly. You could then use the results in your table view.
On 13/05/2008, at 12:27 AM, Steven Huey wrote:
Steven,
In my app I have a similar setup, although without the detail view.
I have the Table Column of my NSOutlineView bound to a
NSTreeController using the Controller Key "arrangedObjects" and the
Model Key Path set to the name of a method in the custom
NSManagedObject subclass that my NSTreeController is managing.
The table columns of my NSTableView are bound to an
NSArrayController whose content set is bound to my
NSTreeController's selection. Each column is then bound to a
property of the entity returned by the array controller's content.
I think you could bind your detail view similarly, to the current
selection of your array controller.
Take a look at: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html
for lots of great examples of how to use bindings.
Best regards,
Steven Huey
--
Steven Huey Software - http://www.stevenhuey.com
On May 12, 2008, at 8:03 AM, Steven Hamilton wrote:
Hi folks,
Continuing my learning into Cocoa I'm developing a personal
finance application. An admirable project I believe since none
available suit my purposes and it always pays to have a project
that one would use to learn from.
I have a simple core data model consisting of AccountGroup,
Account, Transaction and I've jammied these all into a window with
outline view, transaction tableview and detail at the bottom. The
model looks like this;
AccountGroup (Asset, expense, income etc)name (string)
accounts (relationship to Account)Account (Bank, Savings etc)name
(string)
transactions (fetched properties explained below)
credit (relationship to transaction)
debit (relationship to transaction)Transaction
memo (string)
date (date)
amount (NSNumber)
fromAccount (reverse of debit)
toAccount (reverse of credit)
I believe this to be the true model as a transaction is an object
and is of an amount that goes from somewhere to somewhere. This is
double entry accounting. My problem is in presenting this to the
user.
Problem 1
Most finance apps, and mine included you select an account from a
list (my outlineview) and it then displays all the transactions
involved. So I created a fetched property with a predicate that
included any transactions that had the selected account name in
either fromAccount or toAccount. This works to a point. My
tableview displays all the transactions of the selected account
but since its a fetched properties (contentArray) the list isn't
the true transaction array (contentSet), therefore I cannot add to
it using the bound detail table below it.
I must admit the bindings for this are really playing with my
head. I struggled quite immensely getting the selection from the
treecontroller and in the end it started working without me fully
understanding why. I have further complications to come as I have
the decide whether the transaction amount is a debit or credit
(based on the from/to account relationships) and then display the
amount in the correct column and then also work out a way to add
transactions back in like this.
It seems even though I'm set on what I believe to be the correct
data model for this, the method of which a user expects to see
this information is a little too different. Does anyone have any
advice? Have I talked too much?
_______________________________________________
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
--
Steven Huey Software - http://www.stevenhuey.com
_______________________________________________
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