From db51d60ad71d87641511dfd6e5406a5e2ed32c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=A4=91=ED=98=84?= Date: Tue, 12 Nov 2019 14:38:55 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tutorial/Tutorial.playground/Contents.swift | 39 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Tutorial/Tutorial.playground/Contents.swift b/Tutorial/Tutorial.playground/Contents.swift index 9b0d9f6..f3c6b93 100644 --- a/Tutorial/Tutorial.playground/Contents.swift +++ b/Tutorial/Tutorial.playground/Contents.swift @@ -24,9 +24,40 @@ let selectedIndexesFilePath = Bundle.main.path(forResource: "selectedIndexes", o let champsData = FileManager.default.contents(atPath: champsFilePath!) let selectedIndexesData = FileManager.default.contents(atPath: selectedIndexesFilePath!) -let champs = try JSONSerialization.jsonObject(with: champsData!, options: []) -let selectedIndexes = try JSONSerialization.jsonObject(with: selectedIndexesData!, options: []) +struct Champs:Decodable { + let key: String + let name: String +} -// TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라 -let names: [String] = [] +let decoder = JSONDecoder() +let champs = try decoder.decode([Champs].self, from: champsData!) +let selected = try decoder.decode([Int].self, from: selectedIndexesData!) + +var index = 0 +var block: (Champs) -> (Void) +//block = { champs in +// if Int(champs.key) == selected[index] { +// print(champs.name) +// } +// if selected.count > index { +// index += 1 +// } +//} +// +print(champs) + +let value = selected.flatMap { index in + champs.filter { champ in + champ.key == "\(index)" + } +} +let names = value.map{$0.name} print(names) + + +// TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라 +//let names: [String] = [] +//print(names) + + +//selectedIndex대로 챔프 이름을 배열로 불러오면 된다. 챔피언명 5개가 옆에 뜨면 된다.