Lightweight Database Leveldb Https://github.com/google/leveldb
One: Compile leveldb under iOS
Terminal:
1:git Clone Https://github.com/google/leveldb.git
2: Go to the root directory
CD Leveldb-master
3: Compile:
cxxflags=-stdlib=libc++ make Platform=ios
After compiling, LIBLEVELDB.A will be generated in the current directory, supporting all simulators and real machines;
Header file in the Include directory
II: Reference Library
Leveldb is C + +, when using OC. m files to be modified to. mm files;
The compiled library is imported into the Xcode project in group form;
Use OC to refer to
#import "Db.h"
#import "Options.h"
#import "WRITE_BATCH.H"
At this point there will be xxx.h can not find errors;
Directly modify the header file under the Include directory;
Make the following changes to the header file section of the error
This # include "Leveldb/xx.h" changed to include "Xx.h"
Three: Test
#include <iostream> #include <string> #include <assert.h> #include "leveldb/db.h" using namespace St D;int Main (void) {leveldb::D b *db; Leveldb::options Options; Options.create_if_missing = true; Open Leveldb::status Status = leveldb::D b::open (Options, "/tmp/testdb", &db); ASSERT (Status.ok ()); string key = "Name"; String value = "Chenqi"; Write status = Db->put (Leveldb::writeoptions (), key, value); ASSERT (Status.ok ()); Read status = Db->get (Leveldb::readoptions (), key, &value); ASSERT (Status.ok ()); cout<<value<<endl; Delete status = Db->delete (Leveldb::writeoptions (), key); ASSERT (Status.ok ()); Status = Db->get (Leveldb::readoptions (), key, &value); if (!status.ok ()) {cerr<<key<< "" <<status. ToString () <<endl; } else {cout<<key<< "== = "<<value<<endl; }//close delete db; return 0; }
Reference: http://www.tanhao.me/pieces/1397.html/
Http://www.cnblogs.com/haippy/archive/2011/12/04/2276064.html
IOS Lightweight Database Leveldb