I want to fetch persons having the same birthday from CoreData ?
or in general if I have array of persons [Person]
where Person
class as follow
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.
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.
The best way to group in Core Data is with a NSFetchedResultsController
. You can use the date as the sectionNameKeyPath
and it will group automatically for you. The items in the fetched results controller can be easily accessed with index paths, very useful for table views.
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.