-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: home Qeustion Network (#47)
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
SOPKATHON-iOS-TEAM2/SOPKATHON-iOS-TEAM2/Model/HomeViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// HomeViewModel.swift | ||
// SOPKATHON-iOS-TEAM2 | ||
// | ||
// Created by 이지희 on 6/4/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import Moya | ||
|
||
|
||
class HomeViewModel: ObservableObject { | ||
@State var homeQuestions: [DTO.GetQuestionsResponse.Question] = [] | ||
|
||
func getQuestionHome() { | ||
Providers.questionProvier.request(.getQuestions) { result in | ||
switch result { | ||
case .success(let response): | ||
do { | ||
let decoder = JSONDecoder() | ||
let response = try decoder.decode(DTO.GetQuestionsResponse.self, from: response.data) | ||
self.homeQuestions = response.data | ||
} catch { | ||
print("Decoding error: \(error)") | ||
} | ||
|
||
|
||
case .failure(let error): | ||
print(error) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters