I have a lot of core database classes that shares the same two functions (please see below).
It seem there should be a better way to do this? Is it possible to create a generic function / Protocol for this?
final class ChecklistHelper { static let shared = ChecklistHelper() private func fetchFirstInDatabaseWith(predicate: NSPredicate) -> Checklist? { guard let cd = ChecklistCD.mr_findFirst(with: predicate) else { return nil } return Checklist(manageObject: cd) } private func fetchAllInDatabaseWith(predicate: NSPredicate) -> [Checklist]? { guard let cds = ChecklistCD.mr_findAll(with: predicate) as? [ChecklistCD] else { return nil } return cds.map { Checklist(manageObject: $ 0) } } } ... final class RecipieHelper { static let shared = RecipieHelper() private func fetchFirstInDatabaseWith(predicate: NSPredicate) -> Recipie? { guard let cd = RecipieCD.mr_findFirst(with: predicate) else { return nil } return Recipie(manageObject: cd) } private func fetchAllInDatabaseWith(predicate: NSPredicate) -> [Recipie]? { guard let cds = RecipieCD.mr_findAll(with: predicate) as? [RecipieCD] else { return nil } return cds.map { Recipie(manageObject: $ 0) } } }