我有以下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