Ei kuvausta

UserDefaultManager.m 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // UserDefaultManager.m
  3. // FirstLink
  4. //
  5. // Created by unicode on 14-11-24.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "UserDefaultManager.h"
  9. @implementation UserDefaultManager
  10. + (UserDefaultManager *)sharedManager {
  11. static UserDefaultManager *sharedUserDefaultManagerInstance = nil;
  12. static dispatch_once_t once_token;
  13. dispatch_once(&once_token, ^{
  14. sharedUserDefaultManagerInstance = [[self alloc] init];
  15. });
  16. return sharedUserDefaultManagerInstance;
  17. }
  18. - (id)getUserDefaultObject:(NSString *)key {
  19. // return YES;
  20. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  21. return [userDefault objectForKey:key];
  22. }
  23. - (BOOL)setUserDefaultObject:(id)object key:(NSString *)key {
  24. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  25. [userDefault setObject:object forKey:key];
  26. return [userDefault synchronize];
  27. }
  28. - (BOOL)removeUserDefaultKey:(NSString *)key {
  29. if (!key) {
  30. return FALSE;
  31. }
  32. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  33. [userDefault removeObjectForKey:key];
  34. return [userDefault synchronize];
  35. }
  36. + (BOOL)removeAllDataInUserDefault {
  37. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  38. return TRUE;
  39. }
  40. @end