jeudi 30 avril 2015

Can not use sqlite (swift) commands outside viewDidLoad()

Im using the framework SQLite from stephencelis

I have the problem that the commands can be only used within viewDidLoad(). But i have to use the defined variables (e.g. var carlist) in functions outside viewDidLoad.

Where is my logical problem?

My code snipped:

    override func viewDidLoad() {
     super.viewDidLoad()
     let db = Database("/Users/**/Desktop/NEW/car/car.sqlite")      
     let cars = db["cars"]
     let car_id = Expression<Int64>("car_id")
     let car_model = Expression<String?>("car_model")

     for car_list in cars {
        println("car_model: \(car_list[car_model])")
        var carlist[car_list[car_model]] // array
     }
    }

The error, if i move the lines after "let db" to outside: 'ViewController.Type' does not have a member named "db"

Aucun commentaire:

Enregistrer un commentaire