1.

class Employee4 {     var name:String     var  id:Int     init(name:String, id:Int) {         self.name = name         self.id = id     } } func testAssignment() {     let emp1 = Employee4(name: "Sam", id: 1)     let emp2 = Employee4(name: "John", id: 2)     let emp3 = Employee4(name: "Robert", id: 3)     var employees = [emp1,emp2]     let employees2 = employees     employees[0].name = "Sam Smith"     employees.append(emp3)     for emp in employees2 {         print("name \(emp.name)")     } }

Answer»

In MVC, CONTROLLER is coordinated that reads / saves data into the data model and displays data / handles actions in the view.

In MVVM, the view model is a CLOSE representation of a view. The view model is bound to the view. Any change in data in the view model, leads to notifiications and view pulls data from the view model and it displays it.

Test covering controllers can be a bit DIFFICULT as view is tightly attached to a view i.e View controller will have an instance of a view within it. So it will be difficult to mock the view methods called from the controller.

Test covering in  ViewModel is RATHER easy as it does not contain any REFERENCE to a view. Rather it only prepares data for the view only. It is the view that pulls the data from the view model.  Also, the view delegates the action to the View model. 



Discussion

No Comment Found

Related InterviewSolutions