FLEXRuntime+UIKitHelpers.h 3.1 KB

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