Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

core data fetch request

// For this example, the name of my Core Data Entity is 'TaskItem'
// This can be placed in any SwiftUI View Struct to declare a variable array of your core data entries that automatically refreshes on changes to the core data model
@FetchRequest(
    sortDescriptors: [
        NSSortDescriptor(keyPath: TaskItem.dueTime, ascending: true),
        NSSortDescriptor(keyPath: TaskItem.complete, ascending: true)
    ],
    predicate: NSCompoundPredicate(andPredicateWithSubpredicates: [NSPredicate(format: "%K >= %@", #keyPath(TaskItem.dueTime), todayDateFrom! as NSDate)]),
    animation: .default
	) var tasks: FetchedResults<TaskItem>
 
PREVIOUS NEXT
Tagged: #core #data #fetch #request
ADD COMMENT
Topic
Name
3+4 =