FLEXDefaultsExplorerViewController.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // FLEXDefaultsExplorerViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 5/23/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXDefaultsExplorerViewController.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXRuntimeUtility.h"
  11. #import "FLEXDefaultEditorViewController.h"
  12. @interface FLEXDefaultsExplorerViewController ()
  13. @property (nonatomic, readonly) NSUserDefaults *defaults;
  14. @end
  15. @implementation FLEXDefaultsExplorerViewController
  16. - (NSUserDefaults *)defaults
  17. {
  18. return [self.object isKindOfClass:[NSUserDefaults class]] ? self.object : nil;
  19. }
  20. #pragma mark - Superclass Overrides
  21. - (NSString *)customSectionTitle
  22. {
  23. return @"Defaults";
  24. }
  25. - (NSArray *)customSectionRowCookies
  26. {
  27. return [[[self.defaults dictionaryRepresentation] allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
  28. }
  29. - (NSString *)customSectionTitleForRowCookie:(id)rowCookie
  30. {
  31. return rowCookie;
  32. }
  33. - (NSString *)customSectionSubtitleForRowCookie:(id)rowCookie
  34. {
  35. return [FLEXRuntimeUtility descriptionForIvarOrPropertyValue:[self.defaults objectForKey:rowCookie]];
  36. }
  37. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  38. {
  39. UIViewController *drillInViewController = nil;
  40. NSString *key = rowCookie;
  41. id drillInObject = [self.defaults objectForKey:key];
  42. if ([FLEXDefaultEditorViewController canEditDefaultWithValue:drillInObject]) {
  43. drillInViewController = [[FLEXDefaultEditorViewController alloc] initWithDefaults:self.defaults key:key];
  44. } else {
  45. drillInViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:drillInObject];
  46. }
  47. return drillInViewController;
  48. }
  49. - (BOOL)shouldShowDescription
  50. {
  51. return NO;
  52. }
  53. @end