我有以下If-Statment,我想知道如何通過switch語句實現這一點?swift 1.2如果循環切換語句
我試圖表示在陣列中的整數值作爲一個字符串(例如,1 ==「一月」)
func assigningMonthName([Data]) {
for i in dataset.arrayOfDataStructures {
if (i.month) == 1 {
println("Jan")
}
else if (i.month) == 2 {
print("Feb")
}
else if (i.month) == 3 {
print("March")
}
else if (i.month) == 4 {
print("April")
}
else if (i.month) == 5 {
print("May")
}
else if (i.month) == 6 {
print("June")
}
else if (i.month) == 7 {
print("July")
}
else if (i.month) == 8 {
print("August")
}
else if (i.month) == 9 {
print("September")
}
else if (i.month) == 10 {
print("October")
}
else if (i.month) == 11 {
print("November")
}
else if (i.month) == 12 {
print("December")
}
else {
println("Error assigning month name")
}
}
}
任何答案,將不勝感激:)
只是一個建議,找到一種方法,通過使用'NSDate'從詮釋得一個月。它會讓你的生活比使用'if else'或'switch case'更容易 – t4nhpt