Categories
ios swift

Using SQLite.swift To Save Data

Simple example using SQLite.swift. Follow the link to their git repository for more information and further documentation. I went this route for a current project, mainly to use sqlite. I would normally opt for Realm.io since it now has good swift support.

import SQLite

// Get document directory path from your phone
let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String

// Create sqlite database file
let db = Database("\(self.path)/db.sqlite3")

// Get a reference to the table that will be created eventually to query
let contacts_db = db["contacts"]

// Setup the data types for the columns in the table
let id = Expression<Int64>("id")
let name = Expression<String?>("name")
let phone = Expression<String>("phone")
let location = Expression<String>("location")
let tags = Expression<String>("tags")

Force Measuring Devices - These devices are used to measure the viagra soft tabs solboards.com temperature changes inside the body. Spinal care Spinal care treatments are designed to reduce pain and inflammation Nervous system disorders:  tadalafil discount This herb strengthens nervous system. It lowers the self-esteem cheap cialis solboards.com of the person as he might fail to maintain erection for long time. If the woman is not able to feel the power, the power solboards.com levitra properien of the Amazon. // Create the "contacts" table with the supplied column datatypes.
db.create(table: contacts_db, ifNotExists: true) { t in
    t.column(id, primaryKey: .Autoincrement)
    t.column(name)
    t.column(phone)
    t.column(location)
    t.column(tags)
}

// Insert new row into "contacts" table
let insert = contacts_db.insert(name <- "John Doe", phone <- "323-333-3333", location <- "Fat Rabbits", tags <- "Nice, Sweet, Clean")

// Reading the data from "contacts" table
for contact in contacts_db {
            println("id: \(contact[id]), name: \(contact[name]!), phone: \(contact[phone]), location: \(contact[location]), tags: \(contact[tags])")
        }