FLEXArgumentInputViewFactory.m 1.8 KB

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