January 26, 2021

Saving text values in Swift to a SQLite DB

Problems saving text to your SQLite DB in Swift?

I was exploring Swift (having only used Objective-C before) for the first time and was making an app using a simple SQLite database - I was having trouble saving some of the text values to the database and couldn’t understand why. After much searching, I came across this stackoverflow  post - the key was this line:

sqlite3_bind_text(statement, 1, itemName, -1, nil) --> itemName should be UTF8 String

Hopefully the internets will make this a bit more accessible so that others don’t spend the hours I did looking for an answer!