我有一个快速的问题,我不知道如何解决它,因为我只有2个月的学习速度,我正在逐步学习,所以这里是代码:
import Foundation
var dir = "/home/guillermo/Escritorio/";
var file = "tokens";
var path = dir.stringByAppendingPathComponent(file);
guard var archivoTokens = try? String(contentsOfFile: path, encoding: NSUTF8StringEncoding) else {
fatalError("failed to read archivoTokens from file")
}
var lineasArchivoTokens:[String] = archivoTokens.componentsSeparatedByString("\n");
var TOKENS:[String] = [String]();
var PATRONES:[String] = [String]();
var NOMBRES:[String] = [String]();
var count = lineasArchivoTokens.count;
for index in 0..<count{
var tmpList:[String] = (lineasArchivoTokens[index]).componentsSeparatedByString(" ");
PATRONES.append(tmpList[1]);
NOMBRES.append(tmpList[0]);
}
这是错误:
fatal error: Index out of range
Current stack trace:
/usr/lib/swift/linux/libswiftCore.so(swift_reportError+0x8b) [0x7fefd171dccb]
/usr/lib/swift/linux/libswiftCore.so(_swift_stdlib_reportFatalError+0x3d) [0x7fefd172e0cd]
/usr/lib/swift/linux/libswiftCore.so(+0x28d192) [0x7fefd1681192]
/usr/lib/swift/linux/libswiftCore.so(function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> ()+0x34) [0x7fefd1681294]
/usr/lib/swift/linux/libswiftCore.so(+0x16f0b5) [0x7fefd15630b5]
.build/debug/lexico7() [0x40165b]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7fefcf971ec5]
.build/debug/lexico7() [0x401049]
Instrucción ilegal (`core' generado)