Skip to content

Instantly share code, notes, and snippets.

@tifoaudii
Created March 13, 2023 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tifoaudii/88f26df9d3a82810b5a8bf460ae28c5d to your computer and use it in GitHub Desktop.
Save tifoaudii/88f26df9d3a82810b5a8bf460ae28c5d to your computer and use it in GitHub Desktop.
final class SomeViewController: UIViewController {
var isFromHome = false
var isFromCart = false
var isFromProfile = false
var homeService: HomeService = .shared
var cartService: CartService = .shared
var profileService: ProfileService = .shared
private var cards: [CardModel] = []
override func viewDidLoad() {
super.viewDidLoad()
if isFromHome {
homeService.fetchHomeCardModels { [weak self] result in
switch result {
case .success(let cards):
self?.cards = cards
case .failure(let error):
print(error)
}
}
} else if isFromCart {
cartService.fetchCartCardModels { [weak self] result in
switch result {
case .success(let cards):
self?.cards = cards
case .failure(let error):
print(error)
}
}
} else {
profileService.fetchProfileCardModels { [weak self] result in
switch result {
case .success(let cards):
self?.cards = cards
case .failure(let error):
print(error)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment