Latest 0.1.3
Homepage https://github.com/Rannie/RHKeyValueStore
License MIT
Platforms ios 7.0, requires ARC
Dependencies WCDB
Frameworks Foundation
Authors

Key-Value storage tool,based on WCDB (WeChat DataBase).

About WCDB : Tencent/WCDB , 微信WCDB进化之路 – 开源与开始

Easy KV database, can use it instead of NSUserDefaults.

Installation


Add pod 'RHKeyValueStore' to your Podfile and run pod install.
Import <RHKeyValueStore.h>.

Usage


Already #define KeyValueStore [RHKeyValueStore store] ,
so you can use KeyValuStore to get the store instance.

  • Integer
[KeyValueStore setInteger:10 forKey:@"someInteger"];
[KeyValueStore integerForKey:@"someInteger"];
  • Double
[KeyValueStore setDouble:12.4 forKey:@"someDouble"];
[KeyValueStore doubleForKey:@"someDouble"];
  • Bool
[KeyValueStore setBool:YES forKey:@"boolean"];
[KeyValueStore boolForKey:@"boolean"]; 
  • String
[KeyValueStore setString:@"lalal" forKey:@"onestring"];
[KeyValueStore stringForKey:@"onestring"];
  • Object

JSON encoding/decoding

TestObject *obj = [TestObject new];
obj.host = @"github";
obj.ipAddress = @"127.0.0.1";
obj.count = 10;
[KeyValueStore setJsonObject:[obj yy_modelToJSONObject] forKey:@"jsonModel"];

NSDictionary *ano = [KeyValueStore jsonObjectForKey:@"jsonModel"];
TestObject *obj2 = [TestObject yy_modelWithDictionary:ano];

Archive/Unarchive (confirm NSCoding Protocol)

[KeyValueStore setArchiveObject:obj forKey:@"archiveObj"];
TestObject *obj3 = [KeyValueStore unarchiveObjectForKey:@"archiveObj"];
  • Isolation Store

Use method + (instancetype)storeWithLabel:(NSString *)label to create a new table.

Like:

NSString *userId = @"my_user_id";
RHKeyValueStore *userStore = [RHKeyValueStore storeWithLabel:userId];
[userStore setInteger:30 forKey:@"someInteger"];

NSLog(@"global -- %zd, user -- %zd", [KeyValueStore integerForKey:@"someInteger"], [userStore integerForKey:@"someInteger"]);

Console output global -- 10, user -- 30 .

  • Other Methods
// get all keys
NSArray *keys = [KeyValueStore allKeys];
// get pair count
NSUInteger count = [KeyValueStore getKVCount];
// clear current table
[userStore clear];

Documentation


Full API documentation is available on CocoaDocs.

License


The MIT License (MIT)

Copyright (c) 2017 Hanran Liu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Latest podspec

{
    "name": "RHKeyValueStore",
    "version": "0.1.3",
    "summary": "Key-Value storage tool, based on WCDB (WeChat DataBase).",
    "homepage": "https://github.com/Rannie/RHKeyValueStore",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Hanran Liu": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/Rannie/RHKeyValueStore.git",
        "tag": "v0.1.3"
    },
    "source_files": [
        "RHKeyValueStore",
        "RHKeyValueStore/*.{h,m}"
    ],
    "public_header_files": "RHKeyValueStore/*.h",
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "WCDB": [
            "~> 1.0.4"
        ]
    }
}

Pin It on Pinterest

Share This