简体   繁体   中英

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

对于您的特定情况,我假设您将每个用户名作为单独的记录,因此您可以使用-countForFetchRequest:error: NSManagedObjectContext方法来获取给定获取请求如果已传递给executeFetchRequest:error:将返回的对象数executeFetchRequest:error:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM