iOS Xcode

These are sample projects. They include the free version of LiteSync with some limitations (1 table per database + no encryption)

These limitations are not present on the full libraries

SQLite.swift wrapper

There are 2 sample projects using the SQLite.swift wrapper

The first one has a simple interface using SQL:

try db.execute("CREATE TABLE IF NOT EXISTS Tasks (id INTEGER PRIMARY KEY, name TEXT, done INTEGER)") try"INSERT INTO Tasks (name, done) VALUES (?,?)", name, Int(done!)) for row in try db.prepare("SELECT * FROM Tasks") { let id = row[0] as! Int64 let name = row[1] as! String let done = Int(row[2] as! Int64) print("id: \(id) name: \(name) done: \(done)") }


The second one uses objects:

let tasks = Table("tasks") let id = Expression("id") let name = Expression("name") let done = Expression("done") try true) { t in t.column(id, primaryKey: true) t.column(name) t.column(done) }) try <- taskname, done <- isdone!)) for task in try db.prepare(tasks) { print("id: \(task[id]) name: \(task[name]) done: \(task[done])") }


Native SQLite interface

This sample project uses the native SQLite interface

let queryString = "SELECT * FROM Tasks" var stmt:OpaquePointer? if sqlite3_prepare(db, queryString, -1, &stmt, nil) != SQLITE_OK{ let errmsg = String(cString: sqlite3_errmsg(db)!) print("error preparing statement: \(errmsg)") return } while(sqlite3_step(stmt) == SQLITE_ROW){ let id = sqlite3_column_int(stmt, 0) let name = String(cString: sqlite3_column_text(stmt, 1)!) let done = sqlite3_column_int(stmt, 2) print("id: \(id) name: \(name) done: \(done)") } sqlite3_finalize(stmt)



For both projects:

1  Install LiteSync on a computer

2  Start a SQLite shell as the primary node binding to a TCP address

3  Modify the TCP address to connect to on the project code

4  Build and run the project on the simulator or device

To open the database on the primary node we use a command like this:

sqlite3 "file:test.db?node=primary&bind=tcp://"