I am using Xcode and swift. I am trying to create an app that automates receipt documentation instead of traditionally filling in the information in a spreadsheet.
I have used the vision framework to pull data about the receipt and classify it. I was able to classify the essential information (Price, Date, etc), but I'm struggling with how I can store and display the data in a file.
I have looked into the different databases I could use, but I was wondering if there is a short way to upload this data from the app directly to Google Spreadsheets using swift. In short, even if I will go with the database approach, I would still need to display the data in an Excel or CSV way, and I'm unsure of what would be a good approach for that. Any ideas?
CodePudding user response:
You can use sql database but Core Data is very great too if you need to store datas. Specially if you need to sync them with iCloud. In the past i have always use sql but now i find CoreData just better, more clean and more easy (after some time to learn how to use it).
About CSV you can export your datamodel with this sample of code:
// MARK: - Exoprt to CSV
@IBAction func selectorexport(toCSV sender: Any) {
let docPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).map(\.path)[0]
let filePath = URL(fileURLWithPath: docPath).appendingPathComponent("file.csv").path
let contents = String(repeating: "\0", count: 0)
//fill contents with data in csv format
// ...
//var error: Error?
do {
try contents.write(
toFile: filePath,
atomically: true,
encoding: .utf8)
} catch {
}
// check for the error
let fileUrl = URL(fileURLWithPath: filePath)
let activityItems = ["file.csv", fileUrl] as [Any]
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
if let popoverController = activityViewController.popoverPresentationController {
popoverController.barButtonItem = btShare
popoverController.permittedArrowDirections = []
}
// Present action sheet.
present(activityViewController, animated: true)
}