Giter Club home page Giter Club logo

pnduserdefaultscontroller's Introduction

PNDUserDefaultsController is a KVO-compatible controller class. Properties of the shared instance of this class can be bound to user interface elements to access and modify values stored in NSUserDefaults.

PNDUserDefaultsController is a class for iOS 4.3 and newer.

Installation

PNDUserDefaultsController can be added to a project using CocoaPods.

Usage

  1. Subclass PNDUserDefaultsController.m
  2. Add properties for each user default you want to model.
  3. Bind properties to user defaults by overriding +propertiesForUserDefaultsKeys.

Example

In XYUserDefaultsController.h:

//
//  XYUserDefaultsController.h
//
//  Created by Pandamonia LLC on 2/15/13.
//  Copyright (c) 2013 Pandamonia LLC. All rights reserved.
//

#import "PNDUserDefaultsController.h"

extern NSString *const XYUserAcceptedTermsOfServiceKey;
extern NSString *const XYUsernameKey;

@interface XYUserDefaultsController : PNDUserDefaultsController

@property (nonatomic) BOOL acceptedTermsOfService;
@property (nonatomic) NSString *username;

@end

In XYUserDefaultsController.m:

//
//  XYUserDefaultsController.m
//
//  Created by Pandamonia LLC on 2/15/13.
//  Copyright (c) 2013 Pandamonia LLC. All rights reserved.
//

#import "XYUserDefaultsController.h"

NSString *const XYUserAcceptedTermsOfServiceKey = @"XYAcceptedTermsOfService";
NSString *const XYUsernameKey = @"XYUsername";

@implementation XYUserDefaultsController

/*

Depending on your version of Xcode, you may need to  include the following variable synthesis:

@synthesize acceptedTermsOfService = _acceptedTermsOfService;
@synthesize username = _username

*/

+ (NSDictionary *)propertiesForUserDefaultsKeys
{
	static NSDictionary *propertiesForUserDefaultsKeys;
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		propertiesForUserDefaultsKeys = @{
			@"acceptedTermsOfService": XYUserAcceptedTermsOfServiceKey,
			@"username": XYUsernameKey
		};
	});
	
	return propertiesForUserDefaultsKeys;
}

@end

License

PNDUserDefaultsController is created and maintained by Pandamonia LLC under the MIT license. The project itself is free for use in any and all projects. You can use PNDUserDefaultsController in any project, public or private, with or without attribution - though we prefer attribution! It helps us.

Unsure about your rights? Read more.

pnduserdefaultscontroller's People

Contributors

a2 avatar

Stargazers

Simon Strandgaard avatar  avatar Abhineet Majrikar avatar Yas Tabasam avatar Venj avatar Cheng Yao avatar Romain Briche avatar mayulu avatar  avatar

Watchers

 avatar mayulu avatar James Cloos avatar  avatar

Forkers

dinneo

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.