Mickler & Associates, Inc.

View Original

More Progress on Swift App - SQLite and TableViews

More progress was made on my application today and, wow, it took me about six hours to do this, but I finally got it ... 

The animation doesn't really do the code justice, but what it's doing is:

  • Opens a Navigation Controller with the FMDB overlay for accessing SQLite structures - this will allow me to access a SQLite dbase and populate a TableView.
     
  • It looks for the dbase in the documents directory of the current user and, if it exists, drops tbl_contacts, re-creates tbl_contacts, inserts some bogus records into tbl_contacts, and cycles through tbl_contacts to append to an array that's passed to the tableview. All so I can get a selection of humans, as you see here.

The hardest damn thing was to get the code right for appending the values read from the SQL query into an array:

 

 // And populate the array

if let rs = contactDB.executeQuery("SELECT * FROM TBL_CONTACTS", withArgumentsInArray: nil) {

                while rs.next() {

                    // self.contacts = [Contacts(name: rs.stringForColumn("txtname"))]

                    contacts.append(Contacts(name: rs.stringForColumn("txtname")))

                    println("Cycling -")

                    println(rs.stringForColumn("txtname"))

                    }

                } else {

                    println("Select Failed: \(contactDB.lastErrorMessage())")

                }

                println("I'm done cycling")

Anyway, it was crazy how long it took me to get the syntax right, but now I've got a tool to open a dbase, create a query, cycle through the query, populate an array, and pass it to a view ... huge progress today. Much happiness.

R