FLEXRuntime+UIKitHelpers.h 3.2 KB

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