ZXKVStore is an Key-vlaue database written in Swift.The data stored on disk from FMDB.
- [√] key-value store
- [√] counter
- [√] switch
- iOS 7.0 / Mac OS X 10.9
- Xcode 6.4
To use ZXKVStore with a project targeting iOS 7, you must include FMDB in your project.
- Import FMDB (it is recommended to use Cocoapods.)
- If you don't have an bridging header file,create one.(Because FMDB is writen in Objective-C.)
- Drag the ZXKVStore.swift into your project
println(ZXKV["homepage"]) //nil
ZXKV["homepage"] = "http://www.zhangxi.me" // store a value to the key
println(ZXKV["homepage"]) //http://www.zhangxi.me
let array = ["abc","123"]
ZXKV["array"] = array
println(ZXKV["array"]) //["abc","123"]
//any object which implemented NSCoding can be stored.
ZXKV.prefix("100") //Return Array<(key:String,value:AnyObject)> which key begins with prefix("100")
ZXKV.surfix("zx") //Return Array<(key:String,value:AnyObject)> which key ends with surfix("zx")
ZXKV.glob("*zx") //Return Array<(key:String,value:AnyObject)> [GLOB](http://www.runoob.com/sqlite/sqlite-glob-clause.html)
ZXKV.like("%zx") //Return Array<(key:String,value:AnyObject)> [LIKE](http://www.runoob.com/sqlite/sqlite-like-clause.html)
ZXKV.first() //first inserted object
ZXKV.last() //last inserted object
println(ZXKV.count("key")) //0
println(ZXKV.increase("key")) //1
ZXKV.setCount("key", value: 10) //10
println(ZXKV.count("key")) //10
println(ZXKV.decrease("key")) //9
println(ZXKV.count("key")) //9
println(ZXKV.switchState("key")) // nil
println(ZXKV.switchOn("key")) //true,means switch on sucess
println(ZXKV.switchState("key")) //true,the state is true
println(ZXKV.switchOff("key")) //true,means switch off success
println(ZXKV.switchState("key")) //false,means the state is false
println(ZXKV.setSwitchState("key", value: true)) //true,set the state to true,sucess
println(ZXKV.switchState("key")) //true,the state is true
If you're starting a new project in Swift, and just use swift in your old project.You may want to store some data.How? SQLite ? CoreData ? NSUserDefault ? All of this is ok.But you still have another choice , ZXKVStore.It's very light,just drag the ZXKVStore.swift to your project and ZXKV["key"] = value.
When you want to store data.
ZXKVStore mean ZhangXi Key-value store.I'm zhangxi.
ZXKVStore is released under the MIT license. See LICENSE for details.