0
0
iOS Swiftmobile~20 mins

MVVM pattern in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MVVM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding MVVM Roles
In the MVVM pattern, which component is responsible for holding the UI logic and preparing data for display?
AController
BModel
CView
DViewModel
Attempts:
2 left
💡 Hint
Think about which part acts as a bridge between data and UI.
ui_behavior
intermediate
2:00remaining
View Updates in MVVM
In an MVVM iOS app using SwiftUI, when the ViewModel updates a @Published property, what happens to the View?
AThe View automatically refreshes to reflect the new data.
BThe View requires manual refresh calls to update.
CThe Model triggers the View to update directly.
DThe ViewModel must notify the ViewController to update the View.
Attempts:
2 left
💡 Hint
Consider how SwiftUI reacts to changes in @Published properties.
lifecycle
advanced
2:00remaining
ViewModel Lifecycle Management
Which of the following is the best practice to avoid memory leaks when a ViewModel holds a reference to a ViewController in MVVM on iOS?
AUse a strong reference to the ViewController in the ViewModel.
BDo not reference the ViewController at all in the ViewModel.
CUse a weak reference to the ViewController in the ViewModel.
DUse an unowned reference to the ViewController in the ViewModel.
Attempts:
2 left
💡 Hint
Think about how to prevent retain cycles between ViewModel and ViewController.
navigation
advanced
2:00remaining
Navigation Handling in MVVM
In MVVM, where should navigation logic (like pushing a new screen) ideally be handled to keep the ViewModel testable and free of UIKit dependencies?
AInside the View, triggered by ViewModel signals.
BDirectly inside the ViewModel using UIKit calls.
CInside the Model layer.
DInside the AppDelegate.
Attempts:
2 left
💡 Hint
Consider separation of concerns and testability.
🔧 Debug
expert
3:00remaining
Debugging MVVM Data Binding Issue
Given this SwiftUI ViewModel code snippet, why does the View not update when 'count' changes? class CounterViewModel: ObservableObject { var count = 0 func increment() { count += 1 } } What is the cause?
AThe 'increment' method does not call objectWillChange.send(), so View is not notified.
BThe 'count' property is not marked with @Published, so changes are not observed.
CThe ViewModel does not conform to ObservableObject correctly.
DThe View is not observing the ViewModel instance.
Attempts:
2 left
💡 Hint
Check how SwiftUI detects changes in ViewModel properties.