0
0
iOS Swiftmobile~10 mins

Why clean architecture maintains codebases in iOS Swift - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a protocol for the use case layer.

iOS Swift
protocol [1] {
    func execute()
}
Drag options to blanks, or click blank then click option'
AService
BUseCase
CModel
DViewController
Attempts:
3 left
💡 Hint
Common Mistakes
Using ViewController as protocol name mixes UI with business logic.
Using Model or Service does not clearly represent the use case layer.
2fill in blank
medium

Complete the code to inject the dependency in the initializer.

iOS Swift
class Presenter {
    let useCase: [1]

    init(useCase: [1]) {
        self.useCase = useCase
    }
}
Drag options to blanks, or click blank then click option'
AUseCase
BUIViewController
CRepository
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIViewController mixes UI with business logic.
Using Repository or Service without protocol abstraction reduces flexibility.
3fill in blank
hard

Fix the error in the code by choosing the correct layer to handle data fetching.

iOS Swift
class [1] {
    func fetchData() {
        // fetch data from network or database
    }
}
Drag options to blanks, or click blank then click option'
ARepository
BViewController
CPresenter
DUseCase
Attempts:
3 left
💡 Hint
Common Mistakes
Putting fetchData in ViewController mixes UI with data logic.
Presenter or UseCase should not directly fetch data.
4fill in blank
hard

Fill both blanks to complete the clean architecture layers interaction.

iOS Swift
class [1] {
    let repository: [2]

    func execute() {
        repository.fetchData()
    }
}
Drag options to blanks, or click blank then click option'
AUseCase
BViewController
CRepository
DPresenter
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Presenter or ViewController with UseCase.
Assigning ViewController as repository type.
5fill in blank
hard

Fill all three blanks to complete the flow from UI to data layer.

iOS Swift
class [1] {
    let useCase: [2]

    func present() {
        useCase.execute()
    }
}

class [3] {
    func fetchData() {}
}
Drag options to blanks, or click blank then click option'
APresenter
BUseCase
CRepository
DViewController
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing ViewController with Presenter or UseCase.
Assigning ViewController as data fetcher.