Skip to content

Commit e0edbb1

Browse files
committed
add delegate protocol to coredata
1 parent 3c53890 commit e0edbb1

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

AnimalsApp/AnimalsApp/Services/CoreData.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ protocol CoreDataContract: AnyObject {
1717
func saveChanges()
1818
}
1919

20+
protocol UpdateDelegateProtocol: AnyObject {
21+
func updateFavoriteAnimals()
22+
}
23+
2024
class CoreData: CoreDataContract {
2125
static let shared = CoreData()
2226

2327
private var managedContext: NSManagedObjectContext?
28+
29+
var delegate: [UpdateDelegateProtocol]?
2430
var favoriteAnimals = [FavoriteAnimal]() {
2531
didSet {
26-
//completar
32+
delegate?.forEach { delegate in
33+
delegate.updateFavoriteAnimals()
34+
}
2735
}
2836
}
2937

0 commit comments

Comments
 (0)