我试图从文本文件中获取一系列数字,并根据数字定义一个新变量。当我打印SettingsArray时,我得到以下内容:
[10,25,1,0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0, 1,1,25,500,0,1,250,250,250,500,500,500,10,10,10,200,200,200]
我正在寻找的是哪些数字,但出于某种原因,在检查If语句时,所有的SettingsArray元素都是这样的:
[2] String class name = _TtC10Foundation15_NSOpaqueString
显然不符合任何条件,为什么在检查If语句时数组元素会出现乱码?
let file = String(contentsOfFile: "/Users/UserGoesHere/Documents/Settings.txt", encoding: NSUTF8StringEncoding, error: nil)!
var SettingsArray = split(file) {$0 == ","}
var StepPortInvert = ""
if SettingsArray[2] == "1" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
var StepPortInvert = "00000000"
}
if SettingsArray[2] == "0" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
var StepPortInvert = "00000001"
}
if SettingsArray[2] == "1" && SettingsArray[3] == "0" && SettingsArray[4] == "1" {
var StepPortInvert = "00000010"
}
答案 0 :(得分:0)
您只需要声明StepPortInvert一次。 BTW 2,3,4 =" 1,0,0和#34;
let file = String(contentsOfFile: "/Users/UserGoesHere/Documents/Settings.txt", encoding: NSUTF8StringEncoding, error: nil)!
var SettingsArray = split(file) {$0 == ","}
var StepPortInvert = ""
if SettingsArray[2] == "1" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
StepPortInvert = "00000000"
}
if SettingsArray[2] == "0" && SettingsArray[3] == "1" && SettingsArray[4] == "1" {
StepPortInvert = "00000001"
}
if SettingsArray[2] == "1" && SettingsArray[3] == "0" && SettingsArray[4] == "1" {
StepPortInvert = "00000010"
}