//code1
var team = ["김윤","김찬","송성","윤영","정혜"]
for i in team {
print("\(i)")
}
//code2
var team = ["김윤","김찬","송성","윤영","정혜"]
var nextTeam = ["이수","손윤","이제","박채","김하"]
var addTeam = team+nextTeam
for i in addTeam{
print("\(i)")
}
//code3
var teams : [String:String] = [
"김윤":"뉴진스",
"김찬":"아이유",
"송성":"윤성욱",
"윤영":"10cm",
"정혜":"장원영"
]
for (key,value) in teams{
print("\(key):\(value)")
}
//code4
var teams : [String:String] = [
"김윤":"뉴진스",
"김찬":"아이유",
"송성":"윤성욱",
"윤영":"10cm",
"정혜":"장원영"
]
var nextTeams : [String:String] = [
"손윤":"빈지노",
"이제":"아이유",
"박채":"pH-1",
"김하":"아이유"
]
teams.merge(nextTeams){ourTeamKey,_ in ourTeamKey} //기존 teams의 key가 유지됨
var newTeams = teams
for (key,value) in newTeams{
print("\(key):\(value)")
}
//code5-1
var teams : [String:String] = [
"김윤":"뉴진스",
"김찬":"아이유",
"송성":"윤성욱",
"윤영":"10cm",
"정혜":"장원영"
]
var nextTeams : [String:String] = [
"손윤":"빈지노",
"이제":"아이유",
"박채":"pH-1",
"김하":"아이유"
]
teams.merge(nextTeams){i,_ in i}
var newTeams : [Int:String] = [:]
var i=1
for (key,value) in teams{
newTeams.updateValue(value,forKey: i)
i=i+1
}
for (key,value) in newTeams {
print("\(key):\(value)")
}
//code5-2
var ourTeamDict : [[String:String]] = [
[
"name" : "김찬",
"favoriteSinger" : "아이유"
],
[
"name" : "김윤",
"favoriteSinger" : "뉴진스"
],
[
"name" : "송성",
"favoriteSinger" : "윤종신"
],
[
"name" : "윤영",
"favoriteSinger" : "10cm"
],
[
"name" : "정혜",
"favoriteSinger" : "장원영"
]
]
for i in ourTeamDict {
for (key,value) in i {
print("\(key):\(value)")
}
print()
}
//ex
var students: [String: String] = [
"202300001": "홍길동",
"202300008": "고길동",
"200300012": "둘리"
]
print(students.count)
print(students["202300008"] ?? "(없음)")
print(students["202300009", default: "(진짜없음)"])
students["200300012"] = "마이콜"
print(students.count)
print(students)
students["200300032"] = "바요킹"
print(students.count)
print(students)
students["200300032"] = nil
print(students.count)
print(students)
for (number, name) in students {
print("\(number) : \(name)")
}
*/
'PROGRAMMING CODE > SWIFT' 카테고리의 다른 글
[SwiftUI] 버튼을 함수로 리턴하기 (0) | 2023.06.26 |
---|---|
[UIkit] 음성출력예제 (0) | 2023.06.12 |
[Swift] 기초 예제 4 (클래스, 복사) (0) | 2023.06.04 |
[Swift] 기초 예제 2 (함수연습) (0) | 2023.05.31 |
[Swift] 기초 예제 1 (0) | 2023.05.31 |