Latest 0.2
License MIT
Platforms ios 7.0, requires ARC
Dependencies TMCache, PDKeychainBindingsController

MCDynamicObject License MIT

Badge w/ Version
Badge w/ Platform

Automatic persistence for your next iOS project. MCDynamicObject inspects your properties and allows getters to read from and setters to make changes to the underlying data store.


Add the following to your CocoaPods Podfile

pod 'MCDynamicObject'

or clone as a git submodule,

or just copy files in the MCDynamicObject folder into your project.

Setting up

Two concrete singleton subclasses MCDynamicCache (using TMCache) for general-purpose caching and MCDynamicKeychain (using PDKeychainBindingsController) for Keychain Access are provided.

Simply create a subclass and add your own properties:

@interface MCTestingCache : MCDynamicCache

@property (assign, nonatomic) NSUInteger userID;
@property (assign, nonatomic) CGPoint lastTapPoint;

@property (strong, nonatomic) NSString *authToken;
@property (strong, nonatomic) NSDate *lastUpdatedDate;


Remember to make the properties dynamic:

@implementation MCTestingCache

@dynamic userID, lastTapPoint, authToken, lastUpdatedDate;


Then just add water! (Or not…)

Using MCDynamicObject

Read from and write to your properties as normal:

MCTestingCache *cache = [MCTestingCache sharedInstance];

// read and write userID
NSLog(@"userID: %lu", (unsigned long)cache.userID);
cache.userID = 123;

// read and write lastTapPoint
NSLog(@"lastTapPoint: %@", NSStringFromCGPoint(cache.lastTapPoint));
cache.lastTapPoint = CGPointMake(120, 100);

// read and write authToken
NSLog(@"authToken: %@", cache.authToken);
cache.authToken = @"3232n423jn4i32n4i23j4i23j4";

// read and write lastUpdatedDate
NSLog(@"lastUpdatedDate: %@", cache.lastUpdatedDate);
cache.lastUpdatedDate = [NSDate date];

Subclassing MCDynamicObject

You can subclass MCDynamicObject to provide your own data store.

Override - (void)setup to setup your data store. Then override - (id)dynamicValueForKey:(NSString *)key and - (void)setDynamicValue:(id)value forKey:(NSString *)key to provide read and write access.

The getters and setters take a NSObject subclass for objects or NSValue subclass for primitives.


MCDynamicObject is under the MIT license.

Latest podspec

    "name": "MCDynamicObject",
    "version": "0.2",
    "platforms": {
        "ios": "7.0"
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "summary": "Automatic persistence for your next iOS project.",
    "homepage": "",
    "authors": {
        "Matthew Cheok": "[email protected]"
    "requires_arc": true,
    "source": {
        "git": "",
        "branch": "master",
        "tag": "0.2"
    "source_files": "MCDynamicObject/*.{h,m}",
    "public_header_files": "MCDynamicObject/*.h",
    "dependencies": {
        "TMCache": [
            "~> 1.2.0"
        "PDKeychainBindingsController": [
            "~> 0.0.1"
    "subspecs": [
            "name": "Utilities",
            "source_files": "MCDynamicObject/Utilities/*.{h,m}"

Pin It on Pinterest

Share This