Browse Questions
  • Encapsulation, abstraction, inheritance, and polymorphism.
  • All three separate concerns between data, UI, and logic — but they differ in how the middle layer connects to the view.
  • Combine subscriptions and NotificationCenter block observers cause leaks when the observation token is stored on self while the callback closure captures self strongly.
  • OSLog is Apple's structured logging framework.

Answer: All three separate concerns between data, UI, and logic — but they differ in how the middle layer connects to the view.

MVCMVVMMVP
Middle layerControllerViewModelPresenter
View ↔ LogicDirect (tight coupling)Data bindingInterface/protocol
TestabilityHardEasyEasy
iOS default✅ UIKit defaultPopular in SwiftUILess common

MVC (Apple's flavor):

// ViewController does too much — known as "Massive View Controller"
class UserViewController: UIViewController {
    func viewDidLoad() {
        super.viewDidLoad()
        fetchUser()  // network call in VC ❌
    }
}

MVVM:

// ViewModel handles logic, View just renders
class UserViewModel: ObservableObject {
    @Published var displayName = ""
    func load() async { displayName = await fetchUser().name }
}
struct UserView: View {
    @StateObject var vm = UserViewModel()
    var body: some View { Text(vm.displayName).task { await vm.load() } }
}