我试图从字符串中获取字符串数组。我想重复的是不同的符号。
let chars = binaryString.characters.map { String($0) }
for (index, item) in chars {
let activeDay = (index, item)
switch activeDay {
case (Days.Monday.rawValue, "1"):
mondayLabel.textColor = UIColor.blackColor()
case (Days.Monday.rawValue, "0"):
mondayLabel.textColor = UIColor.grayColor()
但Xcode说
Expression type '[String]' is ambiguous without more context
最佳答案
尝试使用Swift的所有优点:
var binaryString = "12312312312312312"
let characters = Array(binaryString.characters)
//Values
for char in characters {
print(char)
}
//Keys and values
for (index, item) in characters.enumerate() {
print(index)
print(item)
}
关于swift - Swift如何从字符串迭代符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39474223/