My Core Data model has an NSDate attribute like here:
@interface DBVial : NSManagedObject
@property (nonatomic, retain) NSDate * updated_at;
How can I get the most recent (according to updated_at) record from all of the records of DBVial? Can I perform it by using NSPredicate?
I know I could fetch all of them and then sort them and get the first one but is it possible to use only NSPredicate instead?
Yup. No need to use
NSPredicate, instead set theNSFetchRequest‘ssortDescriptorto sort records by date, andfetchLimitso you get only the most recent record. Like so: