FLEXArgumentInputViewFactory.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // FLEXArgumentInputViewFactory.m
  3. // FLEXInjected
  4. //
  5. // Created by Ryan Olson on 6/15/14.
  6. //
  7. //
  8. #import "FLEXArgumentInputViewFactory.h"
  9. #import "FLEXArgumentInputView.h"
  10. #import "FLEXArgumentInputJSONObjectView.h"
  11. #import "FLEXArgumentInputNumberView.h"
  12. #import "FLEXArgumentInputSwitchView.h"
  13. #import "FLEXArgumentInputStructView.h"
  14. #import "FLEXArgumentInputNotSupportedView.h"
  15. #import "FLEXArgumentInputStringView.h"
  16. @implementation FLEXArgumentInputViewFactory
  17. + (FLEXArgumentInputView *)argumentInputViewForTypeEncoding:(const char *)typeEncoding
  18. {
  19. Class subclass = [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:nil];
  20. if (!subclass) {
  21. // Fall back to a FLEXArgumentInputNotSupportedView if we can't find a subclass that fits the type encoding.
  22. // The unsupported view shows "nil" and does not allow user input.
  23. subclass = [FLEXArgumentInputNotSupportedView class];
  24. }
  25. return [[subclass alloc] initWithArgumentTypeEncoding:typeEncoding];
  26. }
  27. + (Class)argumentInputViewSubclassForTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  28. {
  29. Class argumentInputViewSubclass = nil;
  30. // Note that order is important here since multiple subclasses may support the same type.
  31. // An example is the number subclass and the bool subclass for the type @encode(BOOL).
  32. // Both work, but we'd prefer to use the bool subclass.
  33. if ([FLEXArgumentInputStringView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  34. argumentInputViewSubclass = [FLEXArgumentInputStringView class];
  35. } else if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  36. argumentInputViewSubclass = [FLEXArgumentInputStructView class];
  37. } else if ([FLEXArgumentInputSwitchView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  38. argumentInputViewSubclass = [FLEXArgumentInputSwitchView class];
  39. } else if ([FLEXArgumentInputNumberView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  40. argumentInputViewSubclass = [FLEXArgumentInputNumberView class];
  41. } else if ([FLEXArgumentInputJSONObjectView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  42. argumentInputViewSubclass = [FLEXArgumentInputJSONObjectView class];
  43. }
  44. return argumentInputViewSubclass;
  45. }
  46. + (BOOL)canEditFieldWithTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  47. {
  48. return [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue] != nil;
  49. }
  50. @end