ipatch
ipatch

Reputation: 4033

How to get a sum for a particular attribute in a CoreData DB?

I recently have just been able to populate my core data DB. I have an attribute named username and I would like to get the total number of users on the system (in the DB) and print it out. I know I need to use NSFetchRequest along with NSEntityDescription. I am just not sure how to go about it. I haven't really seen a question like this on SO. The entity is named Account and my attribute is labeled username

Upvotes: 0

Views: 130

Answers (1)

graver
graver

Reputation: 15213

For your particular case, I suppose you have each username as a separate record so you can use the -countForFetchRequest:error: method of NSManagedObjectContext to get the number of objects a given fetch request would have returned if it had been passed to executeFetchRequest:error:

Upvotes: 2

Related Questions