【发布时间】:2015-10-19 07:45:04
【问题描述】:
我有以下 If-Statment,我想知道如何使用 switch 语句来实现?
我试图将数组中的整数值表示为字符串(例如 1 == "Jan")
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找到从 Int 获取月份的方法。它会让您的生活比使用if else或switch case更轻松
标签: swift if-statement switch-statement