Can we do get and didSet together with lazy keyword. I have an array it fetch data from database (get) and another thing when that array will modify i will call delegate to reload data in didSet.
Its not working and not complain of any error.
class CoreDataManager {
func fetchUsers() -> [UserEntity] {
var users: [UserEntity] = []
do {
users = try! context.fetch(UserEntity.fetchRequest())
}catch {
print("Fetch user Error,", error)
}
return users
}
}
protocol UserControllerToViewModel: AnyObject {
func reloadData()
}
class UserViewModel {
private var manager = CoreDataManager()
weak var delegate: UserControllerToViewModel?
// Here I want to get users and didset together with lazy keyword but its not working
lazy var users: [UserEntity] = manager.fetchUsers() {
didSet {
delegate?.reloadData()
}
}
}
Demo GitHub Project link: https://github.com/YogeshPateliOS/TableView_MVVM.git