简体   繁体   中英

How To Retrive Data In Tableview or Textfield(autocomplete) from a sqlite DataBase file ( citylist.db ) in swift xcode

From past 2 days I am searching over the internet for the link between swift and sqlite but i am unable to get the code for it and for the database connection, as i want retrive the data from the citylist.db file into an auto complete textfield in swift.

Please guys if anybody knows the code or suggest anything about the topic they most welcome..!!

One more thing I went through this link https://github.com/stephencelis/SQLite.swift/blob/master/Documentation/Index.md but stucked on the sqlcipher part and now I dont know what should I do ?

here is sample code to display data using sqlite in table view

 var db : Database!
var cat = Expression<String>("ZCATEGORY")
var name = Expression<String>("ZNAME")
var user : Query!
var stmt : Query!

//@IBOutlet var tabe: UITableView!
override func viewDidLoad() {
    super.viewDidLoad()
    createdb()
}



internal func createdb()
{
    let path = NSBundle.mainBundle().pathForResource("db", ofType: "sqlite")
    println(path)
    db = Database(path, readonly: true)
    user = db["ZFOOD"]
    println(db)
    stmt = user.select(distinct : cat)

}


func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    var data = Array(stmt)
    return data.count

}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var data = Array(stmt)
    let cell: AnyObject = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
    cell.textLabel.text = data[indexPath.row][cat]
    return cell as UITableViewCell
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM