// Created by EasyIOS on 14-4-10.
// Copyright (c) 2014年 zhuchao. All rights reserved.
//
#import "EzUserDefaults.h"
// ----------------------------------
// Source code
// ----------------------------------
#pragma mark -
@implementation EzUserDefaults
DEF_SINGLETON( EzUserDefaults )
- (BOOL)hasObjectForKey:(id)key
{
id value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
return value ? YES : NO;
}
- (id)objectForKey:(NSString *)key
{
if ( nil == key )
return nil;
id value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
return value;
}
- (id)objectForKey:(NSString *)key defaultValue:(id)defaultValue
{
if ( nil == key )
return defaultValue;
id value = [[NSUserDefaults standardUserDefaults] objectForKey:key];
return value ?: defaultValue;
}
- (void)setObject:(id)value forKey:(NSString *)key
{
if ( nil == key || nil == value )
return;
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)removeObjectForKey:(NSString *)key
{
if ( nil == key )
return;
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)removeAllObjects
{
[NSUserDefaults resetStandardUserDefaults];
}
- (id)objectForKeyedSubscript:(id)key
{
return [self objectForKey:key];
}
- (void)setObject:(id)obj forKeyedSubscript:(id)key
{
if ( obj )
{
[self setObject:obj forKey:key];
}
else
{
[self removeObjectForKey:key];
}
}
@end
|