Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

문제 해결 #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
39 changes: 35 additions & 4 deletions Tutorial/Tutorial.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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개가 옆에 뜨면 된다.