Latest 0.0.1
Homepage https://github.com/dreamengine/DEUserDefaults
License MIT
Platforms ios 6.0, requires ARC
Frameworks Foundation
Authors

https://github.com/dreamengine/DEUserDefaults

What It Does

You can do this:

NSString *value = DEUserDefaults[@"key"];
DEUserDefaults[@"key"] = @"value";
[DEUserDefaults synchronize];

instead of this:

NSString *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"key"];
[[NSUserDefaults standardUserDefaults] setObject:@"value" forKey:@"key"];
[[NSUserDefaults standardUserDefaults] synchronize];

DEUserDefaults takes the hassle out of dealing with NSUserDefaults. Just use brackets / subscripting and forget about -standardUserDefaults or -objectForKey:/-setObject:forKey:.

How It Works

Usage

To get/set values from user defaults, simply use keyed subscripting like you would an NSDictionary.

Example

#import "DEUserDefaults.h"

...

-(void)someMethod {
    NSString *someString = DEUserDefaults[@"some_string_key"];

    NSArray *someArray = DEUserDefaults[@"some_array_key"];

    DEUserDefaults[@"number_key"] = @(42);

    [DEUserDefaults synchronize];   // easy to save, too
}

Under the Hood

Technically, DEUserDefaults is a reference to [NSUserDefaults standardUserDefaults] plus an NSUserDefaults category mixed in to handle keyed subscripting. That means that DEUserDefaults is simply an NSUserDefaults instance, and you can use the normal NSUserDefaults object methods on it.

In other words, DEUserDefaults is just syntactic sugar that makes [NSUserDefaults standardUserDefaults] easier to work with.

Example

-(void)someMethod {
    NSDictionary *representation = DEUserDefaults.dictionaryRepresentation;

    [DEUserDefaults registerDefaults:someDictionary];

    NSArray *array = [DEUserDefaults arrayForKey:@"some_array_key"];
}

Latest podspec

{
    "name": "DEUserDefaults",
    "version": "0.0.1",
    "homepage": "https://github.com/dreamengine/DEUserDefaults",
    "authors": {
        "Dream Engine Interactive, Inc.": "[email protected]"
    },
    "social_media_url": "https://twitter.com/dreamengine",
    "summary": "Easy NSUserDefaults subscripting: DEUserDefaults[@"key"] = @"value"",
    "description": "DEUserDefaults takes the hassle out of dealing with NSUserDefaults. Just use brackets/subscripting and forget about -standardUserDefaults or -objectForKey:/-setObject:forKey:. For example, DEUserDefaults[@"key"] = @"value".",
    "platforms": {
        "ios": "6.0"
    },
    "requires_arc": true,
    "frameworks": [
        "Foundation"
    ],
    "source": {
        "git": "https://github.com/dreamengine/DEUserDefaults.git",
        "tag": "0.0.1"
    },
    "source_files": "src/*.{h,m}",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    }
}

Pin It on Pinterest

Share This