How to count in coredata (aggregation)?

后端 未结 2 1184
执念已碎
执念已碎 2021-02-06 11:01

I am learning core data and particularly working on aggregation.

Current what I want to do : count the number of records from the table which is in to-many relations

2条回答
  •  借酒劲吻你
    2021-02-06 11:30

    Jeff LaMarche is just using this as a simple example. In practice, this need is so common that Key-Value Coding has a built in macro to handle it and other common collection operations.

    See: The Key-Value Programming Guide: Set and Array Operators

    In this case you would use the @count operator in your predicate.

    Of course, hand tuning your own expression gives you fine control over your predicates but the operators handle 80% of such task.

提交回复
热议问题