Re: CoreData custom view on NSTableView
Re: CoreData custom view on NSTableView
- Subject: Re: CoreData custom view on NSTableView
- From: "I. Savant" <email@hidden>
- Date: Sat, 15 Dec 2007 20:53:35 -0500
Devraj:
I only skimmed, so forgive me for any mistakes ...
I would like to look up the Apple address book with each of the phone
numbers and see if they an entry and display say their name and a
picture if its available.
This isn't really a Core Data problem, exactly. Bindings operates
independently of Core Data, and all you're really trying to do is get
a bound table column to display some data.
In order to do that, simply review the Key Value Coding related
documentation and design an appropriate accessor. Something like the
following:
- (NSString *)addressBookName
{
// ask self for phone number (via keypath so NSManagedObject
// faults are automatically fired, etc.), search the address
// book records for a match, see if a phone number exists for
// the match, return phone number as string ... otherwise,
// just return the phone number
}
Since your table column will be bound to the
"addressBookName" (which is KVC compliant), a managed object in a Core
Data context will "do the right thing" and look up a related address
book entry. Failing that, it will return the original data upon which
the name lookup is based (the telephone number the managed object
already "knew").
The picture is handled similarly. I'd suggest, however, that you
don't look it up in the AddressBook database each time it's displayed
(read the documentation - many cells are potentially displayed in
short order, so such things should be quick). I'd instead cache the
value the first time it's requested (within the managed object
instance in this case) and return the cache on each subsequent call.
Of course if the AB database is changed between calls, the cache would
be invalid, but 1) how often is that likely to happen and, 2) you
could always implement a "time-to-live" on your cache.
That's how I'd do it - at least tonight. As so often I do on
weekends, I'm replying after enjoying my favorite Beaujolais. :-) Take
my advice with a grain of salt (or a bottle of Beaujolais).
--
I.S.
_______________________________________________
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