# 8주차 토요스터디[8기] C반 ## 참여자 혜모리 무리 카키 ## 2023.02.25 (토) 토요스터디[8기] C반 Week#8 [금주 실험 주제🧑🏻‍🔬] **TableView, JSON** ## TableView ### 📋 Todo - 1. tableView과 CustomCell 만들고, 원하는 정보를 Section에 맞게 tableView에 표시하기 - [작성한 코드 링크](https://github.com/christy-hs-lee/saturday-study/tree/main/tableView_study) ### 💡 새롭게 알게된 점 - `dictionary.map({ $0.key })` map 고차함수를 사용하면 Dictionary의 Key 값들만 뽑아 배열로 만들 수 있다. (map 사용 안할 시 Dictionary.Keys 타입) ## JSON ### 📋 Todo - 1. JSON 형식의 파일을 생성 ``` swift [ { "nickName":"카키", "기수":8, "휴대폰정보":"12Pro" }, { "nickName":"혜모리", "기수":8, "휴대폰정보":"갤럭시S21" }, { "nickName":"무리", "기수":8, "휴대폰정보":"13pro" }, { "nickName":"건디", "기수":7, "휴대폰정보":"13mini" }, { "nickName":"크리스티", "기수":8, "휴대폰정보":"롤리팝2" } ] ``` ### 📋 Todo - 2. JSON 데이터 파싱 ```swift // CamperData.swift struct CamperData: Codable { let nickName: String let generation: Int let phone: String enum CodingKeys: String, CodingKey { case nickName case generation = "기수" case phone = "휴대폰정보" } } // ViewController.swift class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() decodeData() } func decodeData() { let jsonData = JSONDecoder() guard let dataAsset = NSDataAsset(name: "yagomCamper") else { return } do { let data = try jsonData.decode([CamperData].self, from: dataAsset.data) print(data) } catch { print(error.localizedDescription) } } } /* [JSONStudy.CamperData(nickName: "카키", generation: 8, phone: "12Pro"), JSONStudy.CamperData(nickName: "혜모리", generation: 8, phone: "갤럭시S21"), JSONStudy.CamperData(nickName: "무리", generation: 8, phone: "13pro"), JSONStudy.CamperData(nickName: "건디", generation: 7, phone: "13mini"), JSONStudy.CamperData(nickName: "크리스티", generation: 8, phone: "롤리팝2")] */ ``` ### 💡 새롭게 알게 된 점 - contents.json파일이 없어도 파싱에는 문제가 없었다.