I have a music app written in SwiftUI with some models (Song, Artist), and manager class (LibraryManager) which handles adding new song, generating playlist and serves as a player manager. The structure is like below.
class LibraryManager: ObservableObject {
@Published var songs: [Song] = []
@Published var artists: [Artist] = []
@Published var albums: [Album] = []
// Some methods here
}
// MainApp.swift - used to pass libraryManager into each view
let libraryManager = LibraryManager()
....
ContentView().environmentObject(libraryManager)
I recently want to implement CoreData to my app to store my models like Song. I don't want to change a lot of existing code, which means I still want to use the existing LibraryManager to handle these things. However, I found there is no way of using @FetchRequest in class. Any solutions? Or could anyone tell me the convention of the usage of CoreData.