KissNSUserDefaults 0.0.1

KissNSUserDefaults 0.0.1

LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.

  • By
  • CHEN Xian'an

Keep it simple, stupid!

Directly hard code to access keys of NSUSerDefaults is very boring, and painful because NSUserDefaultsDidChangeNotification contains no userInfo.

Make a NSUserDefaults category to access keys via properties is a better way. And it's a bonus if we know which key has been changed.

This is what KissNSUserDefaults project borns to be. What you need to do is to delcare properties in header and @dynamic all in implementation. Run +kiss_setup in +load will generate all accessors for you.


Add NSUserDefaults+KissNSUserDefaults.h and NSUserDefaults+KissNSUserDefaults.m to your project. Make your own NSUserDefaults category, import NSUserDefaults+KissNSUserDefaults.h and run +kiss_setup in your category's +load.

Check NSUserDefaults+KissDemo.(h|m) in demo project for details. And you can add an observer for KissNSUserDefaultsDidChangeNotification to listen changes.


#import "NSUserDefaults+KissNSUserDefaults.h"

@interface NSUserDefaults (KissDemo)

// KissNSUserDefaults currently supports NSObject, NSInteger, float and BOOL types
@property (nonatomic, strong) NSString *string;
@property (nonatomic) NSInteger integer;
@property (nonatomic) CGFloat floatValue;
@property (nonatomic) BOOL boolValue;



#import "NSUserDefaults+KissDemo.h"

@implementation NSUserDefaults (KissDemo)

// KissNSUserDefaults will generate all accessors for you
@dynamic string, integer, floatValue, boolValue;

+ (void)load
  [self kiss_setup];




Under the MIT license. See the LICENSE file for more information.