FLEXArgumentInputViewFactory.m 2.1 KB

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