FLEXDefaultsExplorerViewController.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. - (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie
  38. {
  39. return YES;
  40. }
  41. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  42. {
  43. UIViewController *drillInViewController = nil;
  44. NSString *key = rowCookie;
  45. id drillInObject = [self.defaults objectForKey:key];
  46. if ([FLEXDefaultEditorViewController canEditDefaultWithValue:drillInObject]) {
  47. drillInViewController = [[FLEXDefaultEditorViewController alloc] initWithDefaults:self.defaults key:key];
  48. } else {
  49. drillInViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:drillInObject];
  50. }
  51. return drillInViewController;
  52. }
  53. - (BOOL)shouldShowDescription
  54. {
  55. return NO;
  56. }
  57. @end