Giter VIP home page Giter VIP logo

kcmutabledictionary's Introduction

KCMutableDictionary

KCMutableDictionary is a subclass of NSMutableDictionary that is transparently persisted in your app's keychain. The general idea is to make secure storage of small items in the keychain as easy as using a mutable dictionary.

Four restrictions are imposed:

  1. KCMutableDictionary may not be initialized with data. Use, for example, [KCMutableDictionary dictionary] or KCMutableDictionary.new.

  2. Keys and values are restricted to property list objects, that is, objects that can be serialized with NSPropertyListSerialization. This includes NSData, NSString, NSArray, NSDictionary, NSDate, and NSNumber, but not (for example) NSSet.

  3. Mutable values may be stored in KCMutableDictionary, but they will be replaced with immutable copies.

  4. Reads are fast, but writes are (relatively) slow.

Using KCMutableDictionary

Copy KCMutableDictionary.h and KCMutableDictionary.m to your project and #import "KCMutableDictionary.h" as required. When the dictionary is instantiated ([KCMutableDictionary dictionary] is as good a method as any), it automatically populates itself from the keychain. Stores are synchronous: the dictionary is immediately written to the keychain and then read back (so that the dictionary items are now immutable copies of the originals).

For security reasons, you may not want the dictionary to remain resident in memory once you're done with it. Do not remove items from the dictionary, since this will also remove them from the backing store in the keychain. Instead, release the dictionary by assigning nil to its reference.

The serialized dictionary is stored by default in the keychain with the key <bundleID>.__KCMutableDictionary__. Named dictionaries can be stored in the keychain as well; used the initializer initWithName: to use a dictionary named <bundleID>.__KCMutableDictionary__.<name>.

Acknowledgements

KCMutableDictionary was inspired by Mark Granoff's granoff/Lockbox and a suggestion by Ernesto Rivera. Matt Gallagher has a useful post on the subject of subclassing NSMutableDictionary at Cocoa with Love that I didn't stumble on until too late to save me some time. Thanks also to my many smart friends.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.