Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Tutorial/Tutorial.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,41 @@ import Foundation
{
"key": "266",
"name": "Aatrox",
...
...
},
...
...
]
*/
let champsFilePath = Bundle.main.path(forResource: "champs", ofType: "json")

/*
[
1,
33,
...
1,
33,
...
]
*/
let selectedIndexesFilePath = Bundle.main.path(forResource: "selectedIndexes", ofType: "json")

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: [])

// TODO: selectedIndexes는 챔피언 목록(champs)의 key 번호 들이다. selectedIndexes에 명시된 순서대로 챔피언들의 이름(name)을 나열하라
let names: [String] = []

var names: [String] = []

if let typedChamps = champs as? [[String: Any]], let indexes = selectedIndexes as? [Int] {
names.append(contentsOf:
typedChamps
.filter { champ in
return indexes.contains(Int(champ["key"] as! String)!)
}.map { champ in
return champ["name"] as! String
}
)
}

print(names)