简体   繁体   English

从CoreData获取具有给定属性的相同值的对象?

[英]Fetch objects having the same value for a given property from CoreData?

I want to fetch persons having the same birthday from CoreData ? 我想从CoreData获取生日相同的人吗?

or in general if I have array of persons [Person] where Person class as follow 或一般来说,如果我有很多人[Person] ,则Person类如下

Person {
 var name: String
 var birthday: NSDate
}

and I want to group the persons based on birthday not birthdate, so I want [NSDate:[Person]] dictionary. 并且我想根据生日而不是生日将人分组,所以我想要[NSDate:[Person]]字典。

so could anyone please help me with this? 所以有人可以帮我吗? Any help is appreciated. 任何帮助表示赞赏。

NSDate is precise down to the 10th of a millisecond, so first you will have to make sure all dates have the same hours and seconds. NSDate精确到毫秒的十分之一,因此首先必须确保所有日期都具有相同的小时和秒。

The best way to group in Core Data is with a NSFetchedResultsController . 分组核心数据的最佳方法是使用NSFetchedResultsController You can use the date as the sectionNameKeyPath and it will group automatically for you. 您可以将日期用作sectionNameKeyPath ,它将自动为您分组。 The items in the fetched results controller can be easily accessed with index paths, very useful for table views. 可使用索引路径轻松访问获取的结果控制器中的项目,这对于表视图非常有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从对象数组中提取具有另一个属性等于给定值的项目的属性值数组 - From array of objects extract array of property values for items having another property equal to given value 如何将具有相同属性名称的对象数组转换为从给定数组中的值连接值的对象? JS - How to transform an array of objects with the same property name into the object in which value is concatenated from values in a given array? JS 从给定数组中获取值 - fetch value from a given array 计算具有相同属性值的数组对象 - Calculation on array objects having same property values 为数组中的所有对象设置相同的给定属性值并消除重复项 - Set same value of given property for all objects within array and eliminate duplicates 从对象数组中获取值 - Fetch value from array of an objects 在对象数组中的属性中查找具有最大值的所有对象,并从同一对象返回其他属性的值 - Finding all objects with Max value in a property within an Array of Objects and return values of other property from the same object 在对象数组中查找具有 id 属性最大值的对象 - Find object having maximum value for the `id` property in an array of objects 如何在具有相同属性值的对象旁边的数组中插入对象 - How to insert objects in array next to objects with the same property value 查找具有相同属性值的对象并将它们添加到新的数组属性中 - Find objects with same property value and add them in new array property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM