我想在Swift内的专用调度队列上执行我的couchbase操作。
我调整了此couchbase-example中的代码,并在调度闭包中添加了引用self.
的函数调用。此时我的申请冻结了。我将[unowned self]
附加到我的封闭处,因为我认为它有strong reference
到self
,但这没有帮助。我在这做错了什么?
couchbase-lite-ios-1.0.0,XCode6版本6.0(6A313)
public class MYDao {
private var manager : CBLManager!
private var dispatchQueue : dispatch_queue_t!
public init(){
//Retrieve copy of CBLManager
self.manager = CBLManager.sharedInstance().copy()
//Create dedicated db queue
self.dispatchQueue = dispatch_queue_create("com.myapp.db", DISPATCH_QUEUE_SERIAL)
//Assign db queue to manager
self.manager.dispatchQueue = self.dispatchQueue
}
public func getDb() -> CBLDatabase {
var database : CBLDatabase?
//Dispatch self.manager operation on db queue
dispatch_sync(self.dispatchQueue, {[unowned self] in
//FREEZE
database = self.manager.existingDatabaseNamed("mydb", error: nil)
})
return database;
}
}