FLEXArgumentInputViewFactory.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. @implementation FLEXArgumentInputViewFactory
  15. + (FLEXArgumentInputView *)argumentInputViewForTypeEncoding:(const char *)typeEncoding
  16. {
  17. Class subclass = [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:nil];
  18. if (!subclass) {
  19. // Fall back to a generic FLEXArgumentInputView if we can't find a subclass that supports the type.
  20. // The generic input view does not actually allow input, but it still shows the title of the field.
  21. subclass = [FLEXArgumentInputView class];
  22. }
  23. return [[subclass alloc] initWithArgumentTypeEncoding:typeEncoding];
  24. }
  25. + (Class)argumentInputViewSubclassForTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  26. {
  27. Class argumentInputViewSubclass = nil;
  28. // Note that order is important here since multiple subclasses may support the same type.
  29. // An example is the number subclass and the bool subclass for the type @encode(BOOL).
  30. // Both work, but we'd prefer to use the bool subclass.
  31. if ([FLEXArgumentInputStructView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  32. argumentInputViewSubclass = [FLEXArgumentInputStructView class];
  33. } else if ([FLEXArgumentInputSwitchView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  34. argumentInputViewSubclass = [FLEXArgumentInputSwitchView class];
  35. } else if ([FLEXArgumentInputNumberView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  36. argumentInputViewSubclass = [FLEXArgumentInputNumberView class];
  37. } else if ([FLEXArgumentInputJSONObjectView supportsObjCType:typeEncoding withCurrentValue:currentValue]) {
  38. argumentInputViewSubclass = [FLEXArgumentInputJSONObjectView class];
  39. }
  40. return argumentInputViewSubclass;
  41. }
  42. + (BOOL)canEditFieldWithTypeEncoding:(const char *)typeEncoding currentValue:(id)currentValue
  43. {
  44. return [self argumentInputViewSubclassForTypeEncoding:typeEncoding currentValue:currentValue] != nil;
  45. }
  46. @end