Re: Two simple questions regarding Core-Data
Re: Two simple questions regarding Core-Data
- Subject: Re: Two simple questions regarding Core-Data
- From: Robert Walker <email@hidden>
- Date: Fri, 4 May 2007 12:47:52 -0400
First, it's a common tendency to think about Core Data as if it were
a database. Here is a short excerpt from the Core Data Programming
Guild:
------------------------------------------
What Core Data Is Not
Having given an overview of what Core Data is, it is also useful to
correct some misperceptions and state what it is not.
Core Data is not a database. Core Data provides an infrastructure for
change management and for saving objects to and retrieving them from
persistent storage. It is not in and of itself a database.
------------------------------------------
a) is possible to set the value of an attribute with a predicate? For
example I would to set the 'label' attribute to 1 for all entities
into the managed objects. Is the only way to get the complete array of
these entities and then apply the attribute to each manually"?
As far as I know the answer is basically yes. You are making a
change to each object, there may be other objects using the value
that is changed that need to be notified of the change through KVO.
You don't want the objects being mutated during a fetch request.
b) is possible to get the number of items given from a predicate
results instead of using [resultsArray count]? (a sort of count(*) for
sql, I don't need of the list). Or there is not any issue on general
performances? This action will be repeated lots of time in my app.
Again, this is why I mentioned the excerpt from the Core Data
Programming Guide. My suggestion would be to start your work with
Core Data using the XML data store. This should help you break the
habit of thinking about Core Data like it was a database. In the
case of the XML or binary persistent stores the entire set of data is
loaded into memory when the file is first opened. Then the entire
store gets replaced, atomically, during a save operation. In this
case it become obvious that you count the objects in the array.
A common design pattern when counting a to-many relation is to cache
the count value within an attribute of the source object.
For example if you have the relation Department < 1----------* >
Person then you could add a "personCount" attribute to Department and
write code in Department to observe changes to the people relation to
update your "counter cache." In this case your count operation
would have no need to fire the Person fault simply to get the count
of people within the department.
On May 4, 2007, at 7:25 AM, Hell's KItchen Hell's KItchen wrote:
Hello List,
I'm playinig with core-data framework; it's looks really good but I've
two simple questions:
a) is possible to set the value of an attribute with a predicate? For
example I would to set the 'label' attribute to 1 for all entities
into the managed objects. Is the only way to get the complete array of
these entities and then apply the attribute to each manually"?
b) is possible to get the number of items given from a predicate
results instead of using [resultsArray count]? (a sort of count(*) for
sql, I don't need of the list). Or there is not any issue on general
performances? This action will be repeated lots of time in my app.
Thanks a lot
Michael.
_______________________________________________
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:
40mac.com
This email sent to email@hidden
--
Robert Walker
email@hidden
_______________________________________________
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