Site Search
This has to be my favourite screen and other than the Spots List, probably took the longest to develop. You will find this screen as a pick list when adding Spots and Alerts.
Throughout my career I’ve always loved programming and dealing with data. I love turning unreadable data into something readable. I also love SQL (Structured Query Language). Its the language used by many RDBMS’s (Relational Database Management Systems) like Oracle, SQL Server, Informix, MySQL and DB2 to name a few. I can do very cool things with data using SQL.
When I was thinking about the sites search, the beta group thought it would probably be best to store the data on the device and download it from time to time. The traffic to/from the website would be too much, especially if users were searching for all sites or all WWFF or all VK5 (and we know there are lots of sites in VK5)! I must mention that the beta group have all got IT backgrounds and they gave me so much advice not only about the Parks & Peaks activity but also about IT stuff. They were great to work with.
Core Data or SQLite, that was the question!
This might be a bit more technical if databases are not your thing. I’ve written this for those who might find this site and want to learn more about Swift and databases.
I looked around at the offerings and there wasn’t much that could be stored on an IOS device. Swift has a framework called Core Data. It manages the model layer and is not restricted to database-style applications or client-server behavior. You can use it as the basis for an app like ParksnPeaks. It is very powerful and can also be used for applications such as a vector graphics app or a presentation app. With this comes complexity and I didn’t have a whole lot of time to learn the ins and outs of Core Data. I knew I wanted an SQL based database because it’s my second language and Core Data was not a good fit for me at the time.
I discovered SQLite which is used by Core Data under the hood. It is open source and a lovely database to work with. However, getting it working in Swift was a nightmare as all the calls are C based not Swift based. There are a few wrappers that make it easier to read but then I would have to rely on another library. So far my app is library free.
I learnt at a very young developer age that libraries can be bad news unless you own the source code, even then you may have bugs to contend with in someone else’s code. Lets say for example, we have an application that uses a library that creates a spreadsheet from data you produce. If the library creates a spreadsheet for version A of the spreadsheet program that was released when dinosaurs were still roaming the earth. What happens when you upgrade your spreadsheet program to version E? Will the spreadsheet program recognise the structure of your version A spreadsheet. Some spreadsheet programs are compatible with older formats but you can see the dilemma. I will give library developers a tick though because they do solve some very complex problems and its either write it yourself or use a library. I prefer to cut my own code where possible.
I loaded the SQLite framework into the project and started Googling. There was a book but few of the examples worked, it was only 6 months old too. So I created yet another test app to play with all the SQLite commands and fixed all the problems from the book that were causing errors.
I created the Sites database and originally used some wrapper code to populate it with a handful of sites. That worked well but everytime I used the database in my app, there would be no sites in the database. What the!!!! After more googling, I found out that the database was moving around at a new build each day and the directory names were as long as my backyard. Two of them were made up from hexadecimal numbers. So I put the database in the right place on my Mac and it now works okay.
Pretty soon, my app was selecting data based on the criteria entered by the user. The criteria is the selection of one Award and/or one State and/or a partial site name/ID search. I now have a working set of functions that select, insert and update data in the database. I’ve since used these to insert Alerts into the database, update & delete them. From now on database handling will be a cinch.