Latest 1.2
License MIT
Platforms ios 7.0, osx 10.7, requires ARC

Build Status
CocoaPods Platform
CocoaPods Version
CocoaPods License

WAKeyValuePersistenceStore is a simple, file based Key-Value persistence store.


Create a WAKeyValuePersistenceStore is simple: = WAKeyValuePersistenceStore(
        directory: NSSearchPathDirectory.CachesDirectory,
        name: "Store",
        objectSerializer: WAPersistenceObjectSerializer.keyedArchiveSerializer())

directory is where you want to store the data files. (cache directory, document directory, application support directory… etc.)

name is the store’s name. Stores with the same directory/name combination share the same data storage.

objectSerializer controls how object will be serialized.

For instance, WAPersistenceObjectSerializer.keyedArchiveSerializer() uses NSKeyedArchiver and NSKeyedUnarchiver to serialize/deserialize objects.

WAPersistenceObjectSerializer.passthroughSerializer() is used to directly write the object to the disk. You may want to use this object serializer to store NSData objects.

You can also created custom object serializers by conform to the WAPersistenceObjectSerialization protocol.

Use subscript to store or retrive objects:

var testData = NSProcessInfo.processInfo().globallyUniqueString["data"] = testData
var string =["data"]

Manage the store or get the store’s information


//Get the store's path on disk.
var path: String { get }

//Get the preferred file URL for a key.
func fileURLForKey(key: String) -> NSURL

//Remove objects
func removeAllObjects()

func removeObjectsByLastAccessDate(date: NSDate, progressChangedBlock: ((UInt, UInt, UnsafeMutablePointer<ObjCBool>) -> Void)?)

//Store information
var currentDiskUsage: UInt { get }

var objectCount: UInt { get }

Generics with Swift

There’s a swift extension for WAKeyValuePersistenceStore. You may specify the object type when retriving object from the store.

extension WAKeyValuePersistenceStore {
    public func objectForKey<ValueType>(aKey: String, valueType: ValueType.Type) -> ValueType? {
        if let value = self.objectForKey(aKey) as? ValueType {
            return value
        } else {
            return nil

Also there’s a WAKeyValuePersistenceStoreTypedAccessor<ValueType> class. You may use it to access a store using generics.

For example:

self.typedStore = WAKeyValuePersistenceStoreTypedAccessor<[Int]>(store:
var testData = [0,1,2,3,4,5,6]
self.typedStore["data"] = testData
var array = self.typedStore["data"] //array is [Int]


Either clone the repo and manually add the files in WAKeyValuePersistenceStore directory

or if you use CocoaPods, add the following to your Podfile

pod 'WAKeyValuePersistenceStore'

If you use Swift, you can enable generics support by adding


pod 'WAKeyValuePersistenceStore/Generics'


  • Automatic Reference Counting (ARC)
  • iOS 7.0+
  • Xcode 6.3+


If you find a bug and know exactly how to fix it, please open a pull request. If you can’t make the change yourself, please open an issue after making sure that one isn’t already logged.

Latest podspec

    "name": "WAKeyValuePersistenceStore",
    "version": "1.2",
    "authors": "YuAo",
    "summary": "A file based Key-Value persistence store for iOS.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": ""
    "source": {
        "git": "",
        "tag": "1.2"
    "requires_arc": true,
    "platforms": {
        "ios": "7.0",
        "osx": "10.7"
    "default_subspecs": "Core",
    "subspecs": [
            "name": "Core",
            "source_files": "WAKeyValuePersistenceStore/**/*.{h,m}"
            "name": "Generics",
            "source_files": "WAKeyValuePersistenceStore/WAKeyValuePersistenceStore+Generics.swift",
            "platforms": {
                "ios": "8.0",
                "osx": "10.10"
            "dependencies": {
                "WAKeyValuePersistenceStore/Core": []

Pin It on Pinterest

Share This