在我的应用程序中,我使用的是couchbase lite数据库,但我无法创建数据库:
以下是AppDelegate.swift
import UIKit
private let DatabaseName = "couchbase-swift"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
var window: UIWindow?
var viewC : ViewController!
let database: CBLDatabase!
override init() {
do{
database = try(CBLManager.sharedInstance().databaseNamed(DatabaseName))
}
catch _ {
database = nil
}
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
if database == nil {
print("Unable to initialize Couchbase Lite")
return false
}
//---- Add RootView Controller------
window = UIWindow(frame: UIScreen.mainScreen().bounds)
viewC = ViewController(nibName: "ViewController", bundle: nil)
window?.rootViewController = viewC
window?.makeKeyAndVisible()
return true
}
}
我使用警告获取了nill数据库:
跳过升级:数据库升级类不存在。
*** ASSERTION FAILED:CBLManager.storageType为'SQLite'但未找到CBL_SQLiteStorage类
请告诉我我的代码出了什么问题。为什么我无法创建数据库?
答案 0 :(得分:1)
我认为这正是您所寻找的,这是一个示例,您可以创建新的Couchbase lite管理器实例,创建新的CouchbaseLite数据库实例,然后创建新文档,插入并检索它
var properties = [
"name": "mirco",
"email": "mirco.zeiss@gmail.com",
"repo": "swift-couchbaselite-cheatsheet"
]
//creating a couchbase manager
let manager = CBLManager.sharedInstance()
{
NSLog("creating the database")
let db = try manager.databaseNamed("mydb")
NSLog("Creating the document")
//we then create a document to store the properties
let doc = db.createDocument()
do {
try doc.putProperties(properties)
NSLog("The Document was updated with properties")
print(properties)
} catch {
NSLog("Too bad, things be tight")
print("Oops! the document was not updated")
}
}catch {
print("Oops! the Database was not created")
}
详细信息可以在这里找到 https://github.com/mwanjajoel/CouchBaseTesting/tree/master/CouchBaseTesting
我希望这可以帮助您开始使用CouchBase Lite
答案 1 :(得分:0)
面对相同的问题但不适用于couchbase并通过添加以下标志来解决。 确保将-ObjC标志添加到目标的Other Linker Flags构建设置中。有时它可能会产生上述错误。
由于