- support basic types [int,float,double,bool,string...]
- support Object [Object:NSCode]
- support List
- support HashMap
- support memory cache(LRU)
- support Codeable (V2.0.0)
pod 'SwiftLvDB'
let sldb = SwiftLvDB.sharedInstance
or
let sldb = SwiftLvDB(subName: "sldb")
If you use the same
init:subName
db in multiple threads, make sure that theSwiftLvDB
instance is unique; invokeclose()
beforeinit:subName
let testValue:String = "hello"
let testKey = "testSaveString"
SwiftLvDB.sharedInstance.set(testValue, forKey: testKey)
let testKey = "testSaveString"
let value = SwiftLvDB.sharedInstance.string(forKey: testKey)
struct TestStruct:Codable,Equatable{
var a:Int
var b:String
static func == (lhs: Self, rhs: Self) -> Bool{
return lhs.a == rhs.a && lhs.b == rhs.b
}
}
let testKey = "testSaveCodeable"
let testvalue = TestStruct(a: 1, b: "hello")
try sldb.set(testvalue, forKey: testKey)
sldb.codeableObject(TestStruct.self, forKey: testKey)
let testValue:[Int] = [1,2,3,4,5]
let testKey = "testSaveList"
try sldb.set(testValue, forKey: testKey)
sldb.codeableObject([Int].self, forKey: testKey)
var testValue:[String:Int] = [:]
testValue["1"] = 1
testValue["2"] = 2
let testKey = "testSaveList"
try sldb.set(testValue, forKey: testKey)
sldb.codeableObject([String:Int].self, forKey: testKey)
SwiftLvDB is released under the MIT license. See LICENSE for details.