FLEXRuntime+UIKitHelpers.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // FLEXRuntime+UIKitHelpers.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 12/16/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "FLEXProperty.h"
  10. #import "FLEXIvar.h"
  11. #import "FLEXMethod.h"
  12. #import "FLEXProtocol.h"
  13. #import "FLEXTableViewSection.h"
  14. @class FLEXObjectExplorerDefaults;
  15. /// Model objects of an object explorer screen adopt this
  16. /// protocol in order respond to user defaults changes
  17. @protocol FLEXObjectExplorerItem <NSObject>
  18. /// Current explorer settings. Set when settings change.
  19. @property (nonatomic) FLEXObjectExplorerDefaults *defaults;
  20. /// YES for properties and ivars which surely support editing, NO for all methods.
  21. @property (nonatomic, readonly) BOOL isEditable;
  22. /// NO for ivars, YES for supported methods and properties
  23. @property (nonatomic, readonly) BOOL isCallable;
  24. @end
  25. @protocol FLEXRuntimeMetadata <FLEXObjectExplorerItem>
  26. /// Used as the main title of the row
  27. - (NSString *)description;
  28. /// Used to compare metadata objects for uniqueness
  29. @property (nonatomic, readonly) NSString *name;
  30. /// For internal use
  31. @property (nonatomic) id tag;
  32. /// Should return \c nil if not applicable
  33. - (id)currentValueWithTarget:(id)object;
  34. /// Used as the subtitle or description of a property, ivar, or method
  35. - (NSString *)previewWithTarget:(id)object;
  36. /// For methods, a method calling screen. For all else, an object explorer.
  37. - (UIViewController *)viewerWithTarget:(id)object;
  38. /// For methods and protocols, nil. For all else, an a field editor screen.
  39. /// The given section is reloaded on commit of any changes.
  40. - (UIViewController *)editorWithTarget:(id)object section:(FLEXTableViewSection *)section;
  41. /// Used to determine present which interactions are possible to the user
  42. - (UITableViewCellAccessoryType)suggestedAccessoryTypeWithTarget:(id)object;
  43. /// Return nil to use the default reuse identifier
  44. - (NSString *)reuseIdentifierWithTarget:(id)object;
  45. #if FLEX_AT_LEAST_IOS13_SDK
  46. /// An array of actions to place in the first section of the context menu.
  47. - (NSArray<UIAction *> *)additionalActionsWithTarget:(id)object sender:(UIViewController *)sender API_AVAILABLE(ios(13.0));
  48. /// An array where every 2 elements are a key-value pair. The key is a description
  49. /// of what to copy like "Name" and the values are what will be copied.
  50. - (NSArray<NSString *> *)copiableMetadataWithTarget:(id)object;
  51. /// Properties and ivars return the address of an object, if they hold one.
  52. - (NSString *)contextualSubtitleWithTarget:(id)object;
  53. #endif
  54. @end
  55. // Even if a property is readonly, it still may be editable
  56. // via a setter. Checking isEditable will not reflect that
  57. // unless the property was initialized with a class.
  58. @interface FLEXProperty (UIKitHelpers) <FLEXRuntimeMetadata> @end
  59. @interface FLEXIvar (UIKitHelpers) <FLEXRuntimeMetadata> @end
  60. @interface FLEXMethodBase (UIKitHelpers) <FLEXRuntimeMetadata> @end
  61. @interface FLEXMethod (UIKitHelpers) <FLEXRuntimeMetadata> @end
  62. @interface FLEXProtocol (UIKitHelpers) <FLEXRuntimeMetadata> @end
  63. typedef NS_ENUM(NSUInteger, FLEXStaticMetadataRowStyle) {
  64. FLEXStaticMetadataRowStyleSubtitle,
  65. FLEXStaticMetadataRowStyleKeyValue,
  66. FLEXStaticMetadataRowStyleDefault = FLEXStaticMetadataRowStyleSubtitle,
  67. };
  68. /// Displays a small row as a static key-value pair of information.
  69. @interface FLEXStaticMetadata : NSObject <FLEXRuntimeMetadata>
  70. + (instancetype)style:(FLEXStaticMetadataRowStyle)style title:(NSString *)title string:(NSString *)string;
  71. + (instancetype)style:(FLEXStaticMetadataRowStyle)style title:(NSString *)title number:(NSNumber *)number;
  72. + (NSArray<FLEXStaticMetadata *> *)classHierarchy:(NSArray<Class> *)classes;
  73. @end
  74. /// This is assigned to the \c tag property of each metadata.