IOS Lightweight Database Leveldb

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.