Best way to handle fetch requests?

Good morning!

Pertaining to core data fetch requests, what is the best way to minimize code creation / repetition throughout your swift files?

So far each of my view controllers have their own methods dealing with fetching an Entity. All pretty much identical. Should these be grouped in something such as:

class FetchRequestHelper
{

static func fetchCoreDataEntity( _ context: NSManagedObjectContext ) -> [EnityName]?
{
 let request: NSFetchRequest<EnityName> = NSFetchRequest( entityName: "EntityName" )
    
    do
    {
        let entity = try context.fetch( request )
        
        return entity
    }
    catch
    {
        print("Couldn't Fetch Entity")
    }
    return nil
}

}

About a year in of iOS practice and still trying to learn each day. Feel really slow in the progress so any tips/tricks are greatly appreciated!

I like this idea, but I often add these helper classes per managed object subclass, and add functionality that is useful according to what is being fetched. So a Student object might have a “fetchWithID” helper function. These in turn can make use of a function that looks a little more like the one you have shown except that it will pass as argument an entity name and a predicate.

oo i really like that, will definitely have to experiment with the approach of helper classes per managed object subclass!

Thank you!