I have a text file filled with numbers and reading the content of file as follows
func arrayFromContentsOfFileWithName(fileName: String) -> [String]? {
guard let path = NSBundle.mainBundle().pathForResource(fileName, ofType: "txt") else {
retu nil
}
do {
let content = try String(contentsOfFile:path, encoding: NSUTF8StringEncoding)
retu content.componentsSeparatedByString("n")
} catch _ as NSError {
retu nil
}}
However, when I check for performance, there seems to be a bottleneck at content.componentsSeparatedByString("n") as shown below:
Can someone suggest a way of dealing with this problem? or may be read the entire text file as double in one-go with values separated from each other as follows:
let B1: [Float] = [0.0584000014, 0.0905999988, 0.0916000009, 0.0640999973, 0.0824000016, 0.0960000008, 0.0776999965, 0.0936999992, 0.0908999965, 0.0568999983, 0.0654999986, 0.0535999984, 0.0901999995, 0.0724999979, 0.104900002, 0.0798000023, 0.0962999985, 0.0914999992, 0.0680999979, 0.110100001, 0.0648000017, 0.103299998, 0.077200003, 0.0821999982, 0.0778999999, 0.074000001, 0.0710999966, 0.108499996, 0.060899999, 0.0697000027, 0.0841000006, 0.061900001]

