- Learning SQLite for iOS
- Gene Da Rocha MSc BSc (Hons)
- 442字
- 2021-07-16 12:32:42
The examples of using SQLite with iOS
The following is a simple application on how to use iOS with the SQLite database with Xcode. It outlines the basic steps of creating an application and database, and selecting data.
To get started, let's start Xcode and create a template using the Single View Application choice, as shown in the following screenshot:

Click on the Next button to proceed to the next screen in this process. In the product name field, enter SimpleCalculator for the language, and select Swift. For the devices field, select iPhone. Then, click on the Next button to move onto the next screen, as shown in the following screenshot:

In the following screenshot, select the directory where the code will reside. Now, we can view what the Xcode developer tool has created. Then, select a device to display the information; in our case, use the iPhone 6s.
See the directory for the source code, as shown in the following screenshot:

The following is a screenshot showing the SimpleCalculator application opened in Xcode. Select the iPhone 6s option as the device to develop on:

Next, click on the Play button that will compile and build the application as shown here in both images, and a blank screen will appear:

The preceding screenshot shows the application to be built, and the following screenshot shows a blank screen after the image is compiled and run.
This method gets you to the basics of an iOS application with Swift working as a canvas.
In this brief example, we will use SQLiteDB.swift and String-Extras.swift to work with the SQLite database, including the Bridging-Header.h file. In the Build Settings option, view Objective-C Bridging Header and double-click on it, and bridge it to Bridging-Header.h, and you can also drag it to show that it is linked.
As mentioned previously, add libsqlite3.0.dylib to the linked frameworks by navigating to General | Linked Frameworks and Libraries; then, add Libsqlite3.0.dylib.
Now, rebuild the project to show that it's working:

Click on the Simulator button, and then click on Quit to stop the current compiled simulator program. The program will compile with no problems. Next, a database instance has to be created as shown in the following code. The SQLite.DB.query method is used to execute these commands:
- First an instance is required:
let testdb = SQLiteDB.sharedInstance()
- To run this query, the following code is used with the SQLiteDB.query way:
var theresult = testdb.query("select * from people where county = 'Berks'", parameters: nil) for row in result { println(row["name"]!.asString()) }
- To delete a record for example, follow the following piece of code:
testdb.execute("delete from people where county = 'Bucks' ", parameters: nil)
- 從零構(gòu)建知識(shí)圖譜:技術(shù)、方法與案例
- Java程序設(shè)計(jì)實(shí)戰(zhàn)教程
- GeoServer Cookbook
- JavaScript語言精髓與編程實(shí)踐(第3版)
- Java編程指南:基礎(chǔ)知識(shí)、類庫應(yīng)用及案例設(shè)計(jì)
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優(yōu)化計(jì)算
- Object-Oriented JavaScript(Second Edition)
- ArcGIS By Example
- Learning Unreal Engine Android Game Development
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- 編程風(fēng)格:程序設(shè)計(jì)與系統(tǒng)構(gòu)建的藝術(shù)(原書第2版)
- Learning RSLogix 5000 Programming
- Oracle 11g寶典
- 深入淺出Rust
- 設(shè)計(jì)模式之禪