Search code examples
xcodecore-datansfetchrequestnsexpression

CoreData in XCode create a NSFetchRequest returning all entities from today


Is there any solution to create a NSFetchRequest in the XCode view which is returning all entities from "today"? In the view you can only specify a date but not dynamically define today.

Create a NSFetchRequest in XCode

I know that I can also create a NSFetchRequest directly in the code and there I can specify the date dynamically but I was just wondering if this is also possible directly in XCode without writing any code.


Solution

  • Yes it is possible. You can specify a variable $TODAY and use it in code like so:

    NSFetchRequest *fetchRequest =   [self.managedObjectModel
      fetchRequestFromTemplateWithName:@"ScanFetch" 
      substitutionVariables:@{@"TODAY":[NSDate date]}];