-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from eunho8713/STEP1-2
Step1 2
- Loading branch information
Showing
11 changed files
with
94 additions
and
92 deletions.
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
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
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 |
---|---|---|
@@ -1,34 +1,17 @@ | ||
// | ||
// OpenMarket - ViewController.swift | ||
// Created by yagom. | ||
// Created by yagom. | ||
// Copyright © yagom. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Foundation | ||
|
||
class ViewController: UIViewController { | ||
let network = NetWork() | ||
|
||
let jsonParser = JSONParser() | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
network.getDetailPageData { (result: Result<DetailPage, Error>) in | ||
switch result { | ||
case .success(let data): | ||
print(data.id) | ||
case .failure(let failure): | ||
print(failure) | ||
} | ||
} | ||
|
||
network.getProductData { (result: Result<Product, Error>) in | ||
switch result { | ||
case .success(let data): | ||
print(data.pageNo) | ||
case .failure(let failure): | ||
print(failure) | ||
} | ||
} | ||
|
||
let a = try? jsonParser.getMockData() | ||
print(a?.pageNo) | ||
} | ||
} |
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,19 @@ | ||
// | ||
// JSONParsingError.swift | ||
// OpenMarket | ||
// | ||
// Created by 박도원 on 2022/11/08. | ||
// | ||
|
||
import Foundation | ||
|
||
enum JSONParsingError: Error, LocalizedError { | ||
case jsonDecodingError | ||
|
||
var errorDescription: String { | ||
switch self { | ||
case .jsonDecodingError: | ||
return "json 디코딩 오류" | ||
} | ||
} | ||
} |
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
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,18 @@ | ||
// | ||
// JSONParser.swift | ||
// OpenMarket | ||
// | ||
// Created by 이은호 on 2022/11/09. | ||
// | ||
|
||
import Foundation | ||
|
||
class JSONParser: JSONDecodable { | ||
var product: Product? | ||
|
||
func getMockData() throws -> Product? { | ||
let fileName = "products" | ||
guard let mock = try? mockParsingData(name: fileName, data: product) else { throw NetWorkError.unknownError } | ||
return mock | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,23 @@ | ||
// | ||
// JsonPaser.swift | ||
// OpenMarket | ||
// | ||
// Created by 박도원 on 2022/10/26. | ||
// | ||
|
||
import UIKit | ||
|
||
protocol JSONDecodable { } | ||
|
||
extension JSONDecodable { | ||
func mockParsingData<T: Decodable>(name: String, data: T) throws -> T? { | ||
guard let dataAsset = NSDataAsset(name: name) else { | ||
throw JSONParsingError.jsonDecodingError | ||
} | ||
let jsonDecoder = JSONDecoder() | ||
guard let data = try? jsonDecoder.decode(T.self, from: dataAsset.data) else { | ||
throw JSONParsingError.jsonDecodingError | ||
} | ||
return data | ||
} | ||
} |
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
Binary file not shown.