I’ve three perform contained in the repository class . I’m calling the perform so as first createUser, then submitApplication and at last submitMemorableWord perform . Situation is that if the createUser perform execution is efficiently then it can go to submitApplication perform , then if submitApplication perform execution is efficiently then circulate will go to submitMemorableWord perform.
I’ve set boolean flag into perform execution block if the boolean flag return true then go to subsequent code execution and name the suitable perform. I’ve debug it it and discover out solely createUser perform is known as.
I made boolean tag (success) to true on execute perform after which I’m anticipating it ought to go to submit perform and name submitApplication. I additionally set one other boolean flag submitComplete into submit perform and alter the worth to true when submit perform is return efficiently and at last I’m checking if boolean tag submitComplete return true , which means submit perform code execution is successfull then name full perform and respectfully return the results of the whole perform.
of the by no means name submit or submitApplication perform which is subsequent perform to be known as..
Right here is the code for Repository class….
import Basis
class Repository {
init() {}
func createUser() async throws -> String {
"Consumer"
}
func submitApplication() async throws -> Bool {
true
}
func submitMemorableWord() async throws -> Bool {
true
}
}
Right here is the code for
import Basis UseCase class
class UseCase {
let repository = Repository()
var success: Bool = false
var sumbitComplete: Bool = false
func execute() async throws {
do {
success = true
let createUser = attempt await repository.createUser()
} catch {
success = false
print("error " + error.localizedDescription)
}
func submit() async -> Bool {
if success {
do {
let submit = attempt await repository.submitApplication()
sumbitComplete = true
} catch {
return false
}
}
return true
}
}
func full() async {
if sumbitComplete {
do {
let completeRequest = attempt await repository.submitMemorableWord()
} catch {
print("Sorry sometings went unsuitable..")
}
}
}
}
Right here is code in view controller ..
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
tremendous.viewDidLoad()
Process { await FinalResult() }
}
func FinalResult() async {
let usecase = SimpleUseCase()
do {
let consequence = attempt await usecase.execute()
} catch {
print(error.localizedDescription)
}
}
}