I want to import data from a .csv file, so I have used the CSVImporter https://github.com/Flinesoft/CSVImporter. It works well, but it starts the importing before the other part of the function viewDidLoad is executed.
The following code is only a test but I need either a solution that ensures that the CSVImporter completes importing before the other viewDidLoad code executes or a function which starts automatically after viewDidLoad.
Here is my code:
var Vokabeln: [[String]]?
var i = 0
override func viewDidLoad() {
super.viewDidLoad()
let path = "/Users/---CENSORED---/Documents/TestLöschen/TestLöschen/Vokabeln.csv"
let importer = CSVImporter<[String]>(path: path, delimiter: ";")
importer.startImportingRecords { $0 }.onFinish { importedRecords in
for record in importedRecords {
self.Vokabeln?[self.i][0] = record[0]
self.Vokabeln?[self.i][1] = record[1]
self.Vokabeln?[self.i][2] = record[2]
print("Begin1")
print(record[0])
print(record[1])
print(record[2])
print("End1")
self.i += 1
}
}
print("Begin2")
print(Vokabeln?[0][0])
print(Vokabeln?[0][1])
print(Vokabeln?[0][2])
print(Vokabeln?[1][0])
print(Vokabeln?[1][1])
print(Vokabeln?[1][2])
print("End2")
}
So first it prints "Begin2" and 6 times prints nil. Then, when the function viewDidLoad is finished, it prints "Begin1", then the correct variables and "End1"
Can anybody help me? Thanks.