【发布时间】:2015-02-13 22:07:53
【问题描述】:
我一直在尝试将代码初始化程序放在模型类的init() 函数中,我有这样的:
init?() {
let docsDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let dbPath = docsDir.stringByAppendingPathComponent("app.sqlite")
let dbQueue = FMDatabaseQueue(path: dbPath)
if dbQueue == nil {
NSLog("%@ : %@", "Problem connecting to the db at", __FUNCTION__)
return nil
} else {
NSLog("%@", "Successfully connected to the db")
}
}
当我尝试从该类的另一个函数中使用 dbQueue 时,dbQueue 总是等于 nil 之类的
func anotherFunction() {
dbQueue?.inDatabase{ db in .... }
}
所以当我尝试初始化时:
let db = dbConnector()
db.anotherFunc() // Zilch!
我的问题是为什么会发生这种情况以及如何解决它。请帮忙,我会请托尔祝福你
【问题讨论】: