'Swift TabularData DataFrame.append "Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1ba67cc48)"
i just want to insert value in a DataFrame created from a CSV File.
i have my CSV file with just the header:
ticker;shares;price;date
i create the dataFrame with: guard let myCsvUrl = Bundle.main.url(forResource: "transaction", withExtension: "csv") else { return } let options = CSVReadingOptions(hasHeaderRow: true, delimiter: ";") var dataFrame = try! DataFrame(contentsOfCSVFile: myCsvUrl, options: options)
then i'd like to append rows and save the dataFrame to the CSV file...
this is the whole code i wrote till now:
import UIKit
import TabularData
class ViewController: UIViewController {
@IBOutlet weak var tickerUpdate: UITextField!
@IBOutlet weak var sharesUpdate: UITextField!
@IBOutlet weak var priceUpdate: UITextField!
@IBOutlet weak var dateUpdate: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func tickerText(_ sender: UITextField) {
tickerUpdate.text = sender.text
}
@IBAction func sharesText(_ sender: UITextField) {
sharesUpdate.text = sender.text
}
@IBAction func priceText(_ sender: UITextField) {
priceUpdate.text = sender.text
}
@IBAction func dateText(_ sender: UITextField) {
dateUpdate.text = sender.text
}
@IBAction func processButton(_ sender: UIButton) {
let ticker = String(tickerUpdate.text!)
let shares = String(sharesUpdate.text!)
let price = String(priceUpdate.text!)
let date = String(dateUpdate.text!)
createCSV(ticker: ticker, shares: shares, price: price, date: date)
}
func createCSV(ticker: String, shares: String, price: String, date:String) {
guard let myCsvUrl = Bundle.main.url(forResource: "transaction", withExtension: "csv") else { return }
let options = CSVReadingOptions(hasHeaderRow: true, delimiter: ";")
var dataFrame = try! DataFrame(contentsOfCSVFile: myCsvUrl, options: options) // Mark 1
dataFrame.append(valuesByColumn: ["ticker": ticker, "shares": shares, "price": price,"date": date])
try! dataFrame.writeCSV(to: myCsvUrl)
print(dataFrame)
}
}
as soon as i press the UIButton, the app crashes with "Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1ba67cc48)"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
