From e7e4513588e31c119bdef915235f5fcfdc3c86e9 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 12 Nov 2019 14:46:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B6=80=EB=81=84=EB=9F=BD=EC=8A=B5=EB=8B=88?= =?UTF-8?q?=EB=8B=A4..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tutorial/Tutorial.playground/Contents.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Tutorial/Tutorial.playground/Contents.swift b/Tutorial/Tutorial.playground/Contents.swift index 9b0d9f6..81b26cd 100644 --- a/Tutorial/Tutorial.playground/Contents.swift +++ b/Tutorial/Tutorial.playground/Contents.swift @@ -28,5 +28,17 @@ let champs = try JSONSerialization.jsonObject(with: champsData!, options: []) let selectedIndexes = try JSONSerialization.jsonObject(with: selectedIndexesData!, options: []) // TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라 -let names: [String] = [] +var names: [String] = [] + +let tempChamps = champs as! [[String: Any]] +let tempIndexs = selectedIndexes as! [Int] + +names = tempChamps.filter({ (champs) -> Bool in + return tempIndexs.reduce(false) { (result, key) -> Bool in + return !result ? (champs["key"] as! String) == String(key) : result + } +}).map { + return $0["name"] as! String +} + print(names)