FLEXMirror.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // FLEXMirror.h
  3. // FLEX
  4. //
  5. // Derived from MirrorKit.
  6. // Created by Tanner on 6/29/15.
  7. // Copyright (c) 2015 Tanner Bennett. All rights reserved.
  8. //
  9. #import <Foundation/Foundation.h>
  10. @class FLEXMethod, FLEXProperty, FLEXIvar, FLEXProtocol;
  11. #import <objc/runtime.h>
  12. #pragma mark FLEXMirror
  13. @interface FLEXMirror : NSObject
  14. /// Reflects an instance of an object or \c Class.
  15. /// @discussion \c FLEXMirror will immediately gather all useful information. Consider using the
  16. /// \c NSObject categories provided if your code will only use a few pieces of information,
  17. /// or if your code needs to run faster.
  18. ///
  19. /// If you reflect an instance of a class then \c methods and \c properties will be populated
  20. /// with instance methods and properties. If you reflect a class itself, then \c methods
  21. /// and \c properties will be populated with class methods and properties as you'd expect.
  22. ///
  23. /// @param objectOrClass An instance of an objct or a \c Class object.
  24. /// @return An instance of \c FLEXMirror.
  25. + (instancetype)reflect:(id)objectOrClass;
  26. /// The underlying object or \c Class used to create this \c FLEXMirror instance.
  27. @property (nonatomic, readonly) id value;
  28. /// Whether the reflected thing was a class or a class instance.
  29. @property (nonatomic, readonly) BOOL isClass;
  30. /// The name of the \c Class of the \c value property.
  31. @property (nonatomic, readonly) NSString *className;
  32. @property (nonatomic, readonly) NSArray<FLEXProperty *> *properties;
  33. @property (nonatomic, readonly) NSArray<FLEXIvar *> *ivars;
  34. @property (nonatomic, readonly) NSArray<FLEXMethod *> *methods;
  35. @property (nonatomic, readonly) NSArray<FLEXProtocol *> *protocols;
  36. /// @return A reflection of \c value.superClass.
  37. @property (nonatomic, readonly) FLEXMirror *superMirror;
  38. @end
  39. @interface FLEXMirror (ExtendedMirror)
  40. /// @return The method with the given name, or \c nil if one does not exist.
  41. - (FLEXMethod *)methodNamed:(NSString *)name;
  42. /// @return The property with the given name, or \c nil if one does not exist.
  43. - (FLEXProperty *)propertyNamed:(NSString *)name;
  44. /// @return The instance variable with the given name, or \c nil if one does not exist.
  45. - (FLEXIvar *)ivarNamed:(NSString *)name;
  46. /// @return The protocol with the given name, or \c nil if one does not exist.
  47. - (FLEXProtocol *)protocolNamed:(NSString *)name;
  48. @end