Sorry for repeating a question albeit slightly differently but I've tried everything, searched this forum and google but can't solve this issue. I have a Sqlite database (only 20kb size) which I want to use in a Swift 4 project using Xcode. I've put the database (a .db file) in the folder where Xcode saved my project but when I run the app I get the 'no such table error'. Following the file path in the debug screen takes me to a file of 0kb i.e. empty. I thought I'd solved this by using the path name (i.e. FileManager.default.fileExists(atPath: "/Users/...") but it won't work on my iPhone (only in Simulator) so I've gone back to trying to use the URL approach. I've copied the main bit of code but my suspicion is that there is something either wrong with the first few lines or I haven't filed the .db file in the right place. I have added it to the project inspector, it is associated with the project as the target and it shows under the copy bundle resource bit of the build phases screen. I'm really struggling here so any help really appreciated.
//Function to open Cities database, add cities to array, sort alphabetically and then append "Please select city" at the start of the array
func populatePickerView() {
let fileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let databaseURL = fileURL.appendingPathComponent("Wanderer.db")
let database = FMDatabase(path: databaseURL.absoluteString)
guard database.open() else {
print("Unable to open database")
return
}
do {
let cities:FMResultSet = try database.executeQuery("SELECT City from Cities", values: nil)
while cities.next() {
if let result = cities.string(forColumn: "City") {
cityData.append(result)
}
}
} catch {
print("OOPS, some sort of failure")
}
cityData = cityData.sorted(by: <)
cityData.insert("Please select city", at: 0)
}